Solved

How to change the font of specific substrings in excel workbook

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
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 viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now