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

  Рет қаралды 2,050

greggowaffles

greggowaffles

Жыл бұрын

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
Excel VBA Macro: Resize Range (Table) Pasted As Image In Email Body
14:13
Extract Specific Data from MS Word into Excel with VBA
10:56
Dinesh Kumar Takyar
Рет қаралды 32 М.
Llegó al techo 😱
00:37
Juan De Dios Pantoja
Рет қаралды 56 МЛН
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 14 МЛН
HOW TO DEFINE VARIABLE IN SCILAB !!
13:15
Flink Maths
Рет қаралды 18
How To Copy Multiple Excel Tables To Word Using VBA
25:10
Sigma Coding
Рет қаралды 7 М.
Insert Header And Footer To Word Documents With VBA
6:06
Jie Jenn
Рет қаралды 7 М.
Fast Format with Styles Syntax in Word document using VBA
0:16
How To Work With Paragraphs In Word VBA
16:28
Sigma Coding
Рет қаралды 13 М.
Excel VBA Tip: Add Button to Your Macro (Alternative Options)
3:52