Hi all so I've managed to make this code work for what i needed it to , it opens word , it opens and pastes the table in the desired position on my device.
when I copy the code into my work computer i keep getting a runtime error and it cant open the word document.
any suggestions or any improvements that you can see that i could make to the code would be greatly appreciated. To give you an idea of my level at excel back in April I had no idea how to create a table.
Any help is greatly appreciated.
The code is courtesy of sigma code. with minimal adjustments.
when I copy the code into my work computer i keep getting a runtime error and it cant open the word document.
any suggestions or any improvements that you can see that i could make to the code would be greatly appreciated. To give you an idea of my level at excel back in April I had no idea how to create a table.
Any help is greatly appreciated.
The code is courtesy of sigma code. with minimal adjustments.
VBA Code:
Sub TblWrd()
'declare word Variables
Dim WrdApp As Word.Application
Dim WrdDoc As Word.Document
Dim WrdTbl As Word.Table
Dim wrksht As Worksheet
Dim wrdrange As Word.Range
Dim wrdshp As Word.InlineShape
'declare excel variables
Dim Exceltbl As ListObject
'create a new istance of word
Set WrdApp = New Word.Application
WrdApp.Visible = True
WrdApp.Activate '<- I know the issue is at that line and I know googling will give me the actual answer but id rather undertand what the problem is and why it fails to open world ,[/COLOR][/B]
'open document in word application
Set WrdDoc = WrdApp.Documents.Open("C:\......112.dotx")
'loop through the list objects in the applicaton
For Each Exceltbl In ActiveSheet
'Set Exceltbl = ActiveSheet.ListObjects("TABLE1", "table2", "table3")
Exceltbl.Range.Copy
'pause the excel application for one second
Application.Wait Now() + #12:00:02 AM#
'paste to bookmark
Set wrdrange = WrdDoc.Bookmarks(1).Range
'paste to word
With wrdrange
.PasteExcelTable linkedtoexcel:=True, WordFormatting:=True, RTF:=True
End With
'create a referemce to the table we just pasted
Set WrdTbl = WrdDoc.Tables(WrdDoc.Tables.Count)
WrdTbl.AllowAutoFit = True
WrdTbl.AutoFitBehavior (wdAutoFitWindow)
'create a new page
WrdApp.ActiveDocument.Sections.Add
WrdApp.Selection.GoTo what:=wdGoToPage, which:=wdGoToNext
'clear my clipboard
Application.CutCopyMode = False
Next
Next
End Sub
Last edited by a moderator: