djedidiahw007
New Member
- Joined
- Sep 19, 2022
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
I can seem to figure out why my code is not iterating through each worksheet in the workbook.
Hopefully someone can help me out here.
Hopefully someone can help me out here.
VBA Code:
Sub CopytoWord()
Dim WordApp As Word.Application
Dim DocLoc As String
Dim LastRow As Long
Dim ws As Worksheet
' Begin the loop.
For Each ws In ActiveWorkbook.Worksheets
LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
ws.Range("A1:F" & LastRow).Copy
DocLoc = Range("G2").Value
Set WordApp = CreateObject("word.application")
WordApp.Documents.Open DocLoc
WordApp.Visible = True
WordApp.ActiveDocument.Activate
WordApp.Application.Selection.MoveDown unit:=wdLine, Count:=1000
With WordApp.Selection
.PasteExcelTable LinkedToExcel:=False, WordFormatting:=True, RTF:=True
End With
WordApp.ActiveDocument.Close SaveChanges:=wdSaveChanges
WordApp.Application.Quit
Next ws
End Sub