IRish3538
06-15-2012, 07:49 AM
I have an excel workbook that populates info into a word document thru bookmarks. How I currently have it setup is that the word document needs to be in the same folder as the excel wb so it can open it, populate, and save.
My question is how to reference the word doc if it's embedded inside the wb as an object. Below is how I currently reference the word doc. Any help would be much appreciated. Thanks!!
'Master Sub to Generate the Results Summary Document
Sub Final_Report_Doc()
Dim iTemp As Integer
'Ignore errors to allow for error evaluation
On Error Resume Next
iTemp = GetAttr(ActiveWorkbook.Path & "\Final Report Template.docx")
'Check if error exists and set response appropriately
Select Case Err.Number
Case Is = 0
Direxists = True
Case Else
Direxists = False
End Select
' Creates Word Document and merges all bookmarks.
If Direxists = False Then
msgresults = MsgBox("Please place the file 'Final Report Template.docx' in the same " & _
"folder as the workbook.", vbOKOnly, "Draft Document not Found")
Exit Sub
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Wb = ActiveWorkbook
Path = Wb.Path & "\Final Report Template.docx"
'Create a new Word Session
Set pappword = CreateObject("Word.Application")
'Open document in word
Set docWord = pappword.documents.Add(Path)
'Sub that fills in all the bookmarks of the template
Call FinalReportFill
'Activate word and display document
With pappword
.Visible = True
.ActiveWindow.WindowState = 1
.Activate
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
'Saves the document
ReportYear = Format(Sheet20.Range("c14"), "yyyy")
Path = ActiveWorkbook.Path & "\" & ReportYear & " " & Sheet20.Range("c4") & _
" - " & Sheet20.Range("c5") & " Final Report.docx"
docWord.SaveAs Path
Sheet1.Select
Exit Sub
My question is how to reference the word doc if it's embedded inside the wb as an object. Below is how I currently reference the word doc. Any help would be much appreciated. Thanks!!
'Master Sub to Generate the Results Summary Document
Sub Final_Report_Doc()
Dim iTemp As Integer
'Ignore errors to allow for error evaluation
On Error Resume Next
iTemp = GetAttr(ActiveWorkbook.Path & "\Final Report Template.docx")
'Check if error exists and set response appropriately
Select Case Err.Number
Case Is = 0
Direxists = True
Case Else
Direxists = False
End Select
' Creates Word Document and merges all bookmarks.
If Direxists = False Then
msgresults = MsgBox("Please place the file 'Final Report Template.docx' in the same " & _
"folder as the workbook.", vbOKOnly, "Draft Document not Found")
Exit Sub
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Wb = ActiveWorkbook
Path = Wb.Path & "\Final Report Template.docx"
'Create a new Word Session
Set pappword = CreateObject("Word.Application")
'Open document in word
Set docWord = pappword.documents.Add(Path)
'Sub that fills in all the bookmarks of the template
Call FinalReportFill
'Activate word and display document
With pappword
.Visible = True
.ActiveWindow.WindowState = 1
.Activate
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
'Saves the document
ReportYear = Format(Sheet20.Range("c14"), "yyyy")
Path = ActiveWorkbook.Path & "\" & ReportYear & " " & Sheet20.Range("c4") & _
" - " & Sheet20.Range("c5") & " Final Report.docx"
docWord.SaveAs Path
Sheet1.Select
Exit Sub