Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access/VBA/Excel accessing first sheet in a workbook

Status
Not open for further replies.

martinm

IS-IT--Management
Mar 30, 2001
113
GB
Hi all, I need to convert someone else's Access VBA so that it opens the first sheet in an Excel spreadsheet, and not the named one.
The existing code:
Code:
Set ltb = db.CreateTableDef(strLink_name)

ltb.Connect = xConnection_string
ltb.SourceTableName = xTable   ' e.g. sheet1

I've tried replace xTable (string) with 1 (integer) with no success.

Next I tried (and various simialr approaches!) to get the sheet name to use in the original, with no joy. :
Code:
 Set objXL = New Excel.Application

 With objXL
  
   Set objWkb = .Workbooks.Open(aFileName)
   On Error Resume Next
     
   objWkb.Worksheets(1).Activate
   
   Set objSht = objWkb.ActiveSheet
   
   If Not Err.Number = 0 Then
     WSName = objSht.Name
   End If
   Err.Clear

I'm sure this is simple, but I can't find the solution anywhere!

Ta.
 


Hi,
Code:
 Set objXL = New Excel.Application

 With objXL
  
   On Error Resume Next

   Set objWkb = .Workbooks.Open(aFileName)

   If Err.Number = 0 Then
     WSName = objWkb.worksheet(1).Name
   Else
     Err.Clear   
   End If

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks, I used SkipVought's, minor tweak in case anyone else uses this :

WSName = objWkb.worksheet(1).Name

Needs an 's' added!

WSName = objWkb.worksheetS(1).Name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top