Excel VBA Macro: Create Word Doc & Have Mutliple Text Styles (in the Same File) Heading & SubHeading

Excel VBA Macro: Create Word Doc & Have Mutliple Text Styles (in the Same File) Heading & SubHeading. In this video, we go over how to include multiple text styles in the same word doc. We use our code to alter the text font type, size, color, bold, italicize, and underline, so that we can create headings and sub headings in our word document.
Code:
Sub multiple_text_styles()
Dim objWord
Dim objDoc
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
With objDoc
objDoc.Styles.Add ("MyHeading")
objDoc.Styles.Add ("MySubHeading")
objDoc.Styles.Add ("MyParagraph")
With .Styles("MyHeading").Font
.Name = "Times"
.Size = 30
.Bold = True
.Underline = True
.Italic = False
.textColor = RGB(165, 0, 33)
End With
With .Styles("MySubHeading").Font
.Name = "Arial"
.Size = 20
.Bold = True
.Underline = False
.Italic = True
.textColor = RGB(255, 80, 80)
End With
With .Styles("MyParagraph").Font
.Name = "Times"
.Size = 100
.Bold = False
.Underline = False
.Italic = False
.textColor = RGB(0, 0, 0)
End With
End With
With objWord
.Visible = True
.Activate
With .Selection
.Style = objDoc.Styles("MyHeading")
.typetext ("Introduction")
.typeparagraph
.Style = objDoc.Styles("MySubHeading")
.typetext (ThisWorkbook.Sheets("Sheet1").Cells(1, 1).Text)
.typeparagraph
.Style = objDoc.Styles("MyHeading")
.typetext (ThisWorkbook.Sheets("Sheet1").Cells(2, 1).Text)
End With
End With
End Sub
#ExcelVBA #ExcelMacro

Пікірлер: 6

  • @KatLeFevre
    @KatLeFevre Жыл бұрын

    This was really helpful! Your sounds is great, the pacing is great, and this video made something click in my head that helped me get further along on a work VBA project that I've been struggling with for months. (I'm learning slowly!)

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    So glad to hear that!! I hope your VBA project goes well!! 😊

  • @drewgossage8842
    @drewgossage8842 Жыл бұрын

    Thanks for sharing mate 👍

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    Thanks for watching!

  • @gruhby9546
    @gruhby9546 Жыл бұрын

    Great video! How could I modify pages to be horizontal vs vertical?

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    thanks! you can use this: objDoc.PageSetup.Orientation = 1