Access.2007.VBA.Bibl..

(John Hannent) #1
FIGURE 7.5

Three workbooks in the Excel window.


To open a specific saved workbook, use a procedure like the one listed next, which opens a saved
workbook using the Worksheets collection’s Openmethod and the file name and path:

Public Function OpenSpecificWorkbook()

On Error GoTo ErrorHandler

Dim appExcel As Excel.Application
Dim bks As Excel.Workbooks
Dim sht As Excel.Worksheet
Dim strWorkbook As String

Set appExcel = GetObject(, “Excel.Application”)
strPrompt = “Enter path and title of workbook”
strTitle = “Workbook Name”
strDefault = “D:\Documents\tblContacts2.xls”

strWorkbook = InputBox(prompt:=strPrompt, _
Title:=strTitle, Default:=strDefault)
appExcel.Workbooks.Open (strWorkbook)
Set sht = appExcel.ActiveWorkbook.Sheets(1)

Working with Excel Worksheets 7

Free download pdf