Solved

How to change the font of specific substrings in excel workbook

Posted on 2015-01-20
2
27 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 41

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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 create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now