Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to change the font of specific substrings in excel workbook

Posted on 2015-01-20
2
Medium Priority
?
34 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
1 Comment
 
LVL 43

Accepted Solution

by:
pcelba earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

877 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