How do I set the some letters in an Excel sheet cell to 'BOLD' through ACTXSERVER using MATLAB (R2019a)?
22 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!