I'm making word doc based on excel list.
I'm able to copy and paste the value to word. I have also set up style: heading & color.
Here is my working code:
How to set up List now?
example:
1 (for heading H1)
1.1 (for heading H2)
1.1.1 (for heading H3)
1.1.1.1 (for heading H4)
1.1.1.1.1 (for heading H5)
1.1.1.1.1.1 (for heading H6)
I'm able to copy and paste the value to word. I have also set up style: heading & color.
Here is my working code:
Code:
Dim wb As Workbook
Dim wc As Worksheet
Set wb = ActiveWorkbook
Set wc = wb.Worksheets("Sheet2")
Dim applWord As Word.Application
Dim docWord As Word.Document
Set applWord = New Word.Application
applWord.Visible = True
applWord.WindowState = wdWindowStateMaximize
Set docWord = applWord.Documents.Add
Dim u_row As Long
u_row = wc.Cells(wc.Rows.Count, "A").End(xlUp).Row
Dim s, rtc As String
For u = 21 To u_row
If wc.Range("G" & u).Value <> "" Then
s = wdStyleHeading1
rtc = wc.Range("B" & u).Value & " " & wc.Range("G" & u).Value
ElseIf wc.Range("H" & u).Value <> "" Then
s = wdStyleHeading2
rtc = wc.Range("B" & u).Value & " " & wc.Range("H" & u).Value
ElseIf wc.Range("I" & u).Value <> "" Then
s = wdStyleHeading3
rtc = wc.Range("B" & u).Value & " " & wc.Range("I" & u).Value
ElseIf wc.Range("J" & u).Value <> "" Then
s = wdStyleHeading4
rtc = wc.Range("B" & u).Value & " " & wc.Range("J" & u).Value
ElseIf wc.Range("K" & u).Value <> "" Then
s = wdStyleHeading5
rtc = wc.Range("B" & u).Value & " " & wc.Range("K" & u).Value
ElseIf wc.Range("L" & u).Value <> "" Then
s = wdStyleHeading6
rtc = wc.Range("B" & u).Value & " " & wc.Range("L" & u).Value
End If
With docWord
.Paragraphs.Last.style = .Styles(s)
.Content.InsertAfter rtc
With .Styles(s)
'.Font.Name = "TimesNewRoman"
'.Font.Size = 12
.Font.Color = wdColorBlack
End With
.Content.InsertParagraphAfter
End With
Next u
How to set up List now?
example:
1 (for heading H1)
1.1 (for heading H2)
1.1.1 (for heading H3)
1.1.1.1 (for heading H4)
1.1.1.1.1 (for heading H5)
1.1.1.1.1.1 (for heading H6)
Last edited: