Set up List into Word during or after copy text from excel

Forestq

Active Member
Joined
May 9, 2010
Messages
482
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:

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:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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