Create and open a new, blank workbook:bks.AddMake the workbook visible:appExcel.Application.Visible = TrueErrorHandlerExit:
Exit SubErrorHandler:
If Err = 429 ThenExcel is not running; open Excel with CreateObject:Set appExcel = CreateObject(“Excel.Application”)
Resume Next
Else
MsgBox “Error No: “ & Err.Number & “; Description: “ & _
Err.Description
Resume ErrorHandlerExit
End IfEnd SubThe procedures in this section can be run from macros; each procedure has a macro
whose name is mcrplus the procedure name.The error handler in the preceding procedure is similar to the one used in the Word Automation
code in Chapter 6; sets a reference to the current Excel instance if Excel is running and otherwise
creates a new Excel Application instance using the CreateObjectfunction from a line in the
procedure’s error handler. If you run the CreateNewWorkbookprocedure repeatedly, each time it
runs a new workbook is created within the Excel window, named Book1, Book2, and so forth, as
shown in Figure 7.5.NOTENOTE
Part II Writing VBA Code to Exchange Data between Office Components