Finding Active Excel Sheet from Access?

HelpTheNewbie

New member
Local time
Today, 01:39
Joined
Feb 26, 2007
Messages
7
I set up some code that allows a user to import an Excel file; however one format that will be imported has a variable worksheet name... This is what I have so far, but it depends on the user setting the sheet name to "Sheet1" prior to import...

Set appExcel = GetObject(ImportFile)
appExcel.Application.Visible = False
appExcel.Parent.Windows(1).Visible = True
Set workSheet = appExcel.Worksheets("Sheet1")

Can I change this code to set the worksheet as the only work sheet in the Excel file, or do I need to rename the sheet every time I want to import it into Access?
 
Like all collections (that I know of), you can use syntax similar to

appExcel.Workbooks(1).Worksheets(1).Name

to find the name of the first worksheet. From here you can figure out what you need to import that worksheet by name.
 

Users who are viewing this thread

Back
Top Bottom