Skip to content

Instantly share code, notes, and snippets.

@SalvaJ
Created April 29, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SalvaJ/5f607ff1394cd96f3608 to your computer and use it in GitHub Desktop.
Save SalvaJ/5f607ff1394cd96f3608 to your computer and use it in GitHub Desktop.
This macro VBA example creates a Word doc and fill Form Fiels
Sub OpenPINDoc()
'
' Open PIN Doc Macro for New TN Client
' This example creates a Word doc and fill Form Fiels
Dim xlApp As Object
Dim wdApp As Object
Dim xlString As String
Dim catString As String
Dim storString As String
Dim dotString As String
Dim pinString As String
Sheets("Doc_Index").Select
storString = Sheets("Doc_Index").Range("B2")
dotString = Sheets("Doc_Index").Range("C2")
pinString = storString & dotString
Sheets("Pin_Index").Select
xlvalString = Sheets("Doc_Index").Range("F1")
'Open Word Instance
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
'Open Template as Document
wdApp.Documents.Add Template:=(pinString)
wdApp.Activate
'Prefill Data
With wdApp.ActiveDocument
.FormFields("docCategory").Result = xlvalString
End With
'Clear
Set xlApp = Nothing
Set wdApp = Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment