How do I set the some letters in an Excel sheet cell to 'BOLD' through ACTXSERVER using MATLAB (R2019a)?

22 views (last 30 days)
Say I am setting the value of a cell to "One of these words will be bolded!" . I want to only set the word "these" to bold, and leave the rest alone. Is there a way to index specific characters of the cell, and make them bolded?

Accepted Answer

dpb
dpb on 18 Jun 2021
This isn't MATLAB per se, but Excel VBA/object model syntax Q? A sample VBA function would look something like
lngPos = InStr(ActiveCell.Value, "/")
With ActiveCell.Characters(Start:=1, Length:=lngPos - 1).Font
.FontStyle = "Bold"
End With
where the function bolds the beginning of the cell content up to an embedded slash character--your position is to be determined by whatever logic you wish to use.
Your mission, should you choose to undertake it, is to translate the above VBA to COM syntax...
h = actxserver('Excel.Application')
h.visible = true
h.Workbooks.Add
sheet = h.ActiveWorkbook.Sheets.Item(1);
sheet.Activate
cells = h.ActiveSheet.Range('C1')
set(cells.Font, 'Bold', true)
was posted by TMW Staff moons ago as a template to follow for the cell, you'll have to get the handle of the .Characters data in the cell it appears from the above -- research into the VBA docs will undoubtedly be needed; you may find other more convenient syntax searching there.
  1 Comment
Thomas Mountford
Thomas Mountford on 1 Jul 2021
I could not find a way to translate to COM syntax however, If I saved a macro on another excel file, I could package it with the matlab program and call the macro in any excel file that was generated.

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!