.
I'm using this following macro to create a report in WORD. After FILTERING the data in the EXCEL sheet to obtain the report results I'm seeking, this macro copies that filtered data to a WORD doc in landscape mode.
I want to include at the top of the report the following string : "Report Run On : " & Now
The macro copies the filtered data from row 10 to the bottom then pastes that data into the WORD doc. I'm open to a completely different macro if necessary.
Spent most of today researching the FORUM and the NET for answers. It would appear the issue may be centered on the method used to copy/paste the data in the WORD doc as most all of the examples reviewed
create the report differently. Never worked with WORD before so I'm feeling slightly out of water here.
Anyone have a suggestion ? Thank you so much !
Option Explicit
Sub CopyFilteredToWord()
Dim FirstCell As Range, LastCell As Range
Dim wdApp As Object, WdDoc As Object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set LastCell = Cells(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column)
Range("A10", LastCell).Copy
wdApp.Visible = True
Set WdDoc = wdApp.Documents.Add
' "Report Run On :" & Now
With WdDoc
.Range.PasteExcelTable False, False, False
.Tables(1).PreferredWidthType = 1 'wdPreferredWidthAuto
.PageSetup.Orientation = 1
End With
Application.CutCopyMode = False
Range("A8").Select
End Sub
Bookmarks