Hello all,
I have the following code that i have been piecing together in order to use excel cells to fill in a word document i have several text form fields. Now this is a sub macro within a larger program. The main information that come in is the Target.row information which gives us the location of the information being extracted and placed in the word document.
I have been testing the above code and the problem i am getting is in the red part. First the word document in question "NOC Template.docx" doesn't physically open and then i get an error when the code exam cell G of the target row. Please let me know what i'm doing wrong.
I have the following code that i have been piecing together in order to use excel cells to fill in a word document i have several text form fields. Now this is a sub macro within a larger program. The main information that come in is the Target.row information which gives us the location of the information being extracted and placed in the word document.
Rich (BB code):
Sub NOCDoc(target As Long)
Dim Wordapp As Word.Application
Dim Location As Variant
Set NOCws = ThisWorkbook.Worksheets("NOC")
Set Wordapp = CreateObject("Word.Application")
Wordapp.Documents.Open ("E:\Special Project\NOC Templates\NOC Template.docx")
'Project Entry
If Not NOCws.Cells(target, "G").Value Is Nothing Then
If NOCws.Cells(target, "F").Value < 1000 Then
Wordapp.ActiveDocument.FormFields("TXProject").Result = "Tract " & NOCws.Cells(target, "F").Value & "Unit" & NOCws.Cells(target, "G").Value
Else
Wordapp.ActiveDocument.FormFields("TXProject").Result = "Parcel Map " & NOCws.Cells(target, "F").Value & "Phase" & NOCws.Cells(target, "G").Value
End If
Else
If NOCws.Cells(target, "F").Value < 1000 Then
Wordapp.ActiveDocument.FormFields("TXProject").Result = "Tract " & NOCws.Cells(target, "F").Value
Else
Wordapp.ActiveDocument.FormFields("TXProject").Result = "Parcel Map " & NOCws.Cells(target, "F").Value
End If
End If
'Location
Location = InputBox("Provide the site location of this project.", "Tract / Parcel Location")
Wordapp.ActiveDocument.FormFields("TXLocation").Result = Location
'Developer Information
Wordapp.ActiveDocument.FormFields("TXDeveloper").Result = NOCws.Cells(target, "I").Value
'Project Completion Date
Wordapp.ActiveDocument.FormFields("TXCompletionDate").Result = NOCws.Cells(target, "K").Value
End Sub
I have been testing the above code and the problem i am getting is in the red part. First the word document in question "NOC Template.docx" doesn't physically open and then i get an error when the code exam cell G of the target row. Please let me know what i'm doing wrong.