Change font style of part of my macro

Sethomas5

Board Regular
Joined
Oct 5, 2015
Messages
204
Hello and thank you in advance!! This forum has been so helpful to me these past few weeks. I'm learning a lot too.
I'm running Excel 2013 on Windows 7.

This is the piece of code I am working with:
Code:
.Bookmarks("Oral_Class1").Range.Text = ws.Range("I2").Value & "/" & [COLOR="#FF0000"]ws.Range("G2").Value[/COLOR]

I would like to have the piece in RED be italicized in my word document.

Please let me know if you need clarification.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
This is an Excel forum, not Word, however, given it's VBA, I'm pretty sure this isn't possible.
 
Upvote 0
This is an Excel forum, not Word, however, given it's VBA, I'm pretty sure this isn't possible.

I know. I run the macro out of excel though. I figured there was some way to change the text style of a range value...I just have no idea what the syntax would be.
 
Upvote 0
You probably haven't defined the variable "ws" in your code. For some reason, you won't post your code, so you're just making us guess.
 
Upvote 0
I don't know much about Word but I suspect it would be something like:

Code:
With .Bookmarks("Oral_Class1")
.Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
.range(len(ws.Range("I2").Value) + 1, len(.Range.text)).Font.Italic = True
End With
 
Last edited:
Upvote 0
Sorry everyone, I thought I had posted my code...

Here it is:
Code:
Sub RunThisOne()
Dim objWord As Object
Dim objDoc As Object
Dim ws As Worksheet

    Set objWord = CreateObject("Word.Application")
    
    objWord.Visible = True

    For Each ws In ActiveWorkbook.Worksheets
        
        
        If ws.Name <> "equivalents" And ws.Name <> "Core Category" And ws.Name <> "Sheet4" Then

            ' create new document based on template
            Set objDoc = objWord.Documents.Add("C:\Users\thomassa\Desktop\thistemplate.dotm")      ' change as required

            With objDoc

                .Bookmarks("EKU_Major").Range.Text = ws.Name

                Select Case ws.Range("I1").Value
                
                    Case "Written Communication"
                        .Bookmarks("Writing_Class1").Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
                        .Bookmarks("Writing_Class2").Range.Text = ws.Range("I3").Value & "/" & ws.Range("G3").Value
                    Case "Oral Communication"
                        .Bookmarks("Oral_Class1").Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
                        .Bookmarks("Oral_Class2").Range.Text = ws.Range("I3").Value & "/" & ws.Range("G3").Value
                        .Bookmarks("Oral_Class3").Range.Text = ws.Range("I4").Value & "/" & ws.Range("G4").Value
                     Case "Natural Sciences"
                        .Bookmarks("Science_Class1").Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
                        .Bookmarks("Science_Class2").Range.Text = ws.Range("I3").Value & "/" & ws.Range("G3").Value
                        .Bookmarks("Science_Class3").Range.Text = ws.Range("I4").Value & "/" & ws.Range("G4").Value
                        .Bookmarks("Science_Class4").Range.Text = ws.Range("I5").Value & "/" & ws.Range("G5").Value
                    Case "Foreign Languages"
                        .Bookmarks("Foreign_Class1").Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
                        .Bookmarks("Foreign_Class2").Range.Text = ws.Range("I3").Value & "/" & ws.Range("G3").Value
                        .Bookmarks("Foreign_Class3").Range.Text = ws.Range("I4").Value & "/" & ws.Range("G4").Value
                        .Bookmarks("Foreign_Class4").Range.Text = ws.Range("I5").Value & "/" & ws.Range("G5").Value
                    Case "Heritage"
                        .Bookmarks("Heritage_Class1").Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
                        .Bookmarks("Heritage_Class2").Range.Text = ws.Range("I3").Value & "/" & ws.Range("G3").Value
                        .Bookmarks("Heritage_Class3").Range.Text = ws.Range("I4").Value & "/" & ws.Range("G4").Value
                        .Bookmarks("Heritage_Class4").Range.Text = ws.Range("I5").Value & "/" & ws.Range("G5").Value
                        .Bookmarks("Heritage_Class5").Range.Text = ws.Range("I6").Value & "/" & ws.Range("G6").Value
                    Case "Humanities"
                        .Bookmarks("Humanities_Class1").Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
                        .Bookmarks("Humanities_Class2").Range.Text = ws.Range("I3").Value & "/" & ws.Range("G3").Value
                        .Bookmarks("Humanities_Class3").Range.Text = ws.Range("I4").Value & "/" & ws.Range("G4").Value
                        .Bookmarks("Humanities_Class4").Range.Text = ws.Range("I5").Value & "/" & ws.Range("G5").Value
                        .Bookmarks("Humanities_Class5").Range.Text = ws.Range("I6").Value & "/" & ws.Range("G6").Value
                     Case "Social & Behavioral Sciences"
                        .Bookmarks("Social_Class1").Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
                        .Bookmarks("Social_Class2").Range.Text = ws.Range("I3").Value & "/" & ws.Range("G3").Value
                        .Bookmarks("Social_Class3").Range.Text = ws.Range("I4").Value & "/" & ws.Range("G4").Value
                        .Bookmarks("Social_Class4").Range.Text = ws.Range("I5").Value & "/" & ws.Range("G5").Value
                        .Bookmarks("Social_Class5").Range.Text = ws.Range("I6").Value & "/" & ws.Range("G6").Value
                        .Bookmarks("Social_Class6").Range.Text = ws.Range("I7").Value & "/" & ws.Range("G8").Value
                        .Bookmarks("Social_Class7").Range.Text = ws.Range("I8").Value & "/" & ws.Range("G9").Value
                    Case "Quantitative Reasoning"
                        .Bookmarks("Quantitative_Class1").Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
                        .Bookmarks("Quantitative_Class2").Range.Text = ws.Range("I3").Value & "/" & ws.Range("G3").Value
                        .Bookmarks("Quantitative_Class3").Range.Text = ws.Range("I4").Value & "/" & ws.Range("G4").Value
                    Case "Computer Literacy"
                        .Bookmarks("Computer_Class1").Range.Text = ws.Range("I2").Value & "/" & ws.Range("G2").Value
                        .Bookmarks("Computer_Class2").Range.Text = ws.Range("I3").Value & "/" & ws.Range("G3").Value
                End Select
 

                .SaveAs ThisWorkbook.Path & "\" & ws.Name & ".docx"

                .Close

            End With

            Set objDoc = Nothing
        End If

    Next ws

    objWord.Quit

    Set objWord = Nothing

End Sub
 
Upvote 0
It looks like the Word object model has Range as a member of the Bookmark class, so try this for each of your bookmark references:

Code:
.Bookmarks("Writing_Class1").Range.Font.Italic=true
 
Upvote 0

Forum statistics

Threads
1,225,743
Messages
6,186,773
Members
453,370
Latest member
juliewar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top