I am taking the error "User-Defined type not defined" every time in line 3 (word.document).
Have you set a reference to "Microsoft Word 16.0 Object Library"? By the error I guess the reference is missing.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I am trying to write a VBA code that transfers data from Excel to Word and saves it as a Word file according to the information in Excel. However, I am taking the error "User-Defined type not defined" every time in line 3 (word.document). Can you please help me to figure out what the error is?
Private Sub CommandButton1_Click()
Dim WrdApp As Object
WrdApp = CreateObject("word.application")
Dim Template As word.document
Row = InputBox("What is the number of the row?")
ATF_template = Cells(2, 3).Value
ATF_Save_Location = Cells(3, 3).Value
Set Template = WrdApp.documents.Open(ATF_template, , False)
WrdApp.Visible = True
doc.Bookmarks("date").Range.InsertAfter Cells(row, 1)
doc.Bookmarks("name").Range.InsertAfter Cells(row, 2)
doc.SaveAs2 "ATF_Save_Location" & "ATF-" & Cells(row, 1).Text & "-" & Cells(row, 2).Text
Template.Close
WrdApp.Quit
MsgBox ("Data Sent")
End Sub
I am taking the error "User-Defined type not defined" every time in line 3 (word.document).
Have you set a reference to "Microsoft Word 16.0 Object Library"? By the error I guess the reference is missing.