Solved

How to change the font of specific substrings in excel workbook

Posted on 2015-01-20
2
28 Views
Last Modified: 2016-08-28
I would like to bold and change the font color of a substring in an excel workbook with multiple worksheets.  All of the cells in the workbook have text.  Using the Excel Replace command changes the entire text in the cell.

Seems like a basic need, but either I'm missing something, or it requires a macro of some sorts to do this.

Thanks,
Bret
0
Comment
Question by:Bret
2 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 40560942
I've found following way which uses IE to create the right format:
Sub Sample()
    Dim Ie As Object

    Set Ie = CreateObject("InternetExplorer.Application")

    With Ie
        .Visible = False

        .Navigate "about:blank"

        .document.body.InnerHTML = "<html><p>This is <b>bold</b> or <i>italic</i></p></html>"

        .document.body.createtextrange.execCommand "Copy"
        ActiveSheet.Paste Destination:=Sheets("Sheet1").Range("A1")

        .Quit
    End With
End Sub

Open in new window

So you may try colors (the whole cell must have one back color) and fonts.

You don't need IE in fact... Following OLE Automation code also works, so it could give you some ideas... (the conversion to VBA should be easy):
oex = CREATEOBJECT('excel.application')
oex.Visible = .t.
oex.Workbooks.Add
_cliptext =  '<html><p>This is <b>bold</b> or <i>italic</i><font size="3" color="red"> red text!</font></p></html>'
oex.ActiveSheet.Range('A2').PasteSpecial

Open in new window

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question