I should also Add that I'm checking to see if Excel was running already, so
that I won't inadvertantly close it if I run into a problem with this macro.
Here's some of the code I have related to the workbook opens:
'Start Excel
'If Excel is running, get a handle on it; otherwise start a new instance of
Excel
On Error Resume Next
Set obXlTestApp = GetObject(, "Excel.Application")
If Err Then
blXlExcelWasNotRunning = True
Set obXlTestApp = Excel.Application
End If
On Error GoTo Err_Handler
'Let the Excel application be visible to the user
obXlTestApp.Visible = True
'Open the workbook stored in "vrXlTestTemplateFullname" Note: Open uses the
Folder and Filename (FullName)
Set obXlTestFile = Workbooks.Open(FileName:=vrXlTestTemplateFullName)
'Save the template as a new file using "vrXlTestFullName" Note: Save and
SaveAs uses the Folder and Filename (FullName)
'By using SaveAs, the original template is automatically closed and does not
need to be closed "manually"
ActiveWorkbook.SaveAs FileName:=vrXlTestFullName
'Open the workbook stored in "vrXlTraceTemplateFullname" Note: Open uses the
Folder and Filename (FullName)
Set obXlTraceFile = Workbooks.Open(FileName:=vrXlTraceTemplateFullName)
'Save the template as a new file using "vrXlTraceFullName" Note: Save and
SaveAs uses the Folder and Filename (FullName)
'By using SaveAs, the original template is automatically closed and does not
need to be closed "manually"
ActiveWorkbook.SaveAs FileName:=vrXlTraceFullName
(bunch of code. If there's an error with text from the Word document,
control is transferred to the label "Err_Handler")
'If the workbook obXlTestFile was open (if it was Not Nothing), then close it.
If Not obXlTestFile Is Nothing Then
obXlTestFile.Close
End If
'If the workbook obXlTraceFile was open (if it was Not Nothing), then close
it.
If Not obXlTraceFile Is Nothing Then
obXlTraceFile.Close
End If
'If Excel was runing when this macro started, leave it running. There are
probably other workbooks open.
'If Excel was Not running when this macro started (blXlExcelWasNotRunning =
False) then quit Excel
If blXlExcelWasNotRunning = True Then
obXlTestApp.Quit
End If
'Set the Objects to "Nothing" to initialize the object
Set obXlTestApp = Nothing
'Set obXlTraceApp = Nothing
Set obXlTestFile = Nothing
Set obXlTraceFile = Nothing
Set obXlTestSheet = Nothing
Set obXlTraceSheet = Nothing
Set obXlRange = Nothing
Set obWdApp = Nothing
Set obWdDoc = Nothing