J
John
I have generated a Word document summarizing some Excel calculations. Excel is the parent program. I would like to be able to edit the Word document that has been created to save the Excel calculations (it has previously been saved as “temporary_report.docâ€) – i.e., make this document visible and active. The following code behind a button on user form works sporadically; usually only the first time that the button is clicked (in most cases the desired Word document won’t become visible and active. I apologize for any goofy coding – I have been losing patience. Any help/advice would be appreciated.
Thanks.
Private Sub btnEditReport_Click()
'
Dim oWord As Word.Application
Dim docFileName As String
Dim docPath As String
Dim oTargetDoc As Word.Document
Dim blTargetDocOpen As Boolean
'
' frmMore.Hide
'
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
MsgBox "You must create the report first."
Else
docFileName = "temporary_report.doc"
For Each oTargetDoc In Documents
If oTargetDoc.Name = docFileName Then
blTargetDocOpen = True
docPath = oTargetDoc.Path & "\" & oTargetDoc.Name
End If
Next oTargetDoc
If blTargetDocOpen = True Then
Documents(docFileName).Activate
Excel.Application.Windows(frmFile.strFileNameReport).Activate
Excel.Application.Windows(frmFile.strFileNameReport).Visible = True
Excel.Application.Windows(frmFile.strFileNameReport).WindowState = xlMaximized
oWord.WindowState = wdWindowStateMaximize
Else
MsgBox "You must create the report first."
End If
End If
'
' frmMore.Show
'
End Sub
Thanks.
Private Sub btnEditReport_Click()
'
Dim oWord As Word.Application
Dim docFileName As String
Dim docPath As String
Dim oTargetDoc As Word.Document
Dim blTargetDocOpen As Boolean
'
' frmMore.Hide
'
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
MsgBox "You must create the report first."
Else
docFileName = "temporary_report.doc"
For Each oTargetDoc In Documents
If oTargetDoc.Name = docFileName Then
blTargetDocOpen = True
docPath = oTargetDoc.Path & "\" & oTargetDoc.Name
End If
Next oTargetDoc
If blTargetDocOpen = True Then
Documents(docFileName).Activate
Excel.Application.Windows(frmFile.strFileNameReport).Activate
Excel.Application.Windows(frmFile.strFileNameReport).Visible = True
Excel.Application.Windows(frmFile.strFileNameReport).WindowState = xlMaximized
oWord.WindowState = wdWindowStateMaximize
Else
MsgBox "You must create the report first."
End If
End If
'
' frmMore.Show
'
End Sub