Try, is it that what you mean ?
Option Explicit
Sub Button1_Click()
Dim wtq As Long
Dim cell As Object, exltbl As Object
Dim wrdApp As Object, wrdDoc As Object
On Error Resume Next
Set wrdApp = GetObject(Class:="Word.Application")
If wrdApp Is Nothing Then
Err.Clear
Set wrdApp = CreateObject(Class:="Word.Application")
If wrdApp Is Nothing Then
MsgBox "Microsoft Word could not be found - Aborting"
Exit Sub
End If
End If
On Error GoTo 0
Application.ScreenUpdating = False
Application.EnableEvents = False
With ThisWorkbook.Sheets("Sheet2")
Set exltbl = .Range("A1:D13")
For Each cell In .Range("A3:A12").Cells
If cell.Value = 0 Then cell.EntireRow.Hidden = True
Next
End With
With wrdApp
.Application.ScreenUpdating = False
Set wrdDoc = .Documents.Open(ThisWorkbook.Path & "\" & "vba.docx") '"F:\vba.docx"
' ".Visible = True" => ? Can it be perhaps/rather set to "False" ?
'Then "wrdApp.Application.ScreenUpdating = False/True" is unnecessary
.Visible = True
.Activate
With wrdDoc
wtq = .Range.Tables.Count
If wtq > 0 Then
With .ActiveWindow.Selection
.EndKey Unit:=6 ' 6 = wdStory
.TypeParagraph
.InsertBreak Type:=7 ' 7 = wdPageBreak
End With
End If
exltbl.SpecialCells(xlCellTypeVisible).Copy
.Paragraphs(.Paragraphs.Count).Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
Application.CutCopyMode = False
.Tables(wtq + 1).AutoFitBehavior (2) ' 2 = wdAutoFitWindow
.Save
.Close
End With
Set wrdDoc = Nothing
.Visible = False
.Application.ScreenUpdating = True
.Quit
End With
Set wrdApp = Nothing
With ThisWorkbook.Sheets("Sheet2")
exltbl.Rows.Hidden = False
End With
Set exltbl = Nothing
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Bookmarks