Hi there,
Let me know if this code stub helps you work this one out?
Kind regards
Private Sub DataToWordTemplate()
Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document
Dim lComboBoxIndex As Long
On Error Resume Next
Set oWordApp = GetObject(, "Word.Application")
If Not Err.Number = 0 Then
Err.Clear
Set oWordApp = New Word.Application
End If
On Error GoTo ErrorHandler
oWordApp.Visible = True
' Provide the path to your template
Set oWordDoc = oWordApp.Documents.Add("C:\WordTemplate.dotx", False, wdNewBlankDocument, True)
' Code stub for one form field
lComboBoxIndex = Me.ComboBox1.ListIndex
If lComboBoxIndex >= 0 Then
' To set the text in a FormField
If oWordDoc.FormFields.Count >= 1 Then
' Where Text1 is the Name you gave to the Form Field
oWordDoc.FormFields.Item("Text1").Result = Me.ComboBox1.List(lComboBoxIndex)
End If
End If
CleanUp:
Set oWordDoc = Nothing
Set oWordApp = Nothing
Exit Sub
ErrorHandler:
MsgBox "An error has occurred." & vbCr & vbCr & _
Err.Number & " " & Err.Description
Err.Clear
GoTo CleanUp
End Sub
|