Hello,
I have an excel document which I have created from a word document by saving as a html file and then a excel file. So that it retains the word formatting for the table. Now I want to add a Active X macro button to save it back to a word document. Currently this is my code, and it is giving me a "compile error: user defined type not defined" error.
Private Sub CommandButton1_Click()
Dim tblRange As Excel.Range
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim WordTable As Word.Table
Set tblRange = ThisWorkbook.Worksheets("CSV LOG TEMPLATE").Range("B2:L169")
On Error Resume Next
Set WordApp = GetObject(class:="Word.Application")
If WordApp Is Nothing Then Set WordApp = CreateObject(class:="Word.Application")
WordApp.Visible = True
WordApp.Activate
Set WordDoc = WordApp.Documents.Add
tblRange.Copy
WordDoc.Paragraphs(1).Range.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=False
Set WordTable = WordDoc.Tables(1)
WordTable.AutoFitBehavior (wdAutoFitWindow)
End Sub
Any help would be appreciated to get it running.
Thanks,
Jana
Bookmarks