ActiveWorksheet vs Worksheets.Item(1)
Seeing JE McGimpsey's response makes me realize I didn't fully digest your
question, in particular that you want to reference the first worksheet
irrespective as to which is the Activsheet. Your code was right first time,
stick with -
Set oWs = oWb.Worksheets.Item(1)
or
Set oWs = oWb.Worksheets(1)
and for future refernce keep in mind your 'ActiveWorkSheet' should have read
ActiveSheet
Regards,
Peter T
"Peter T" <peter_t@discussions wrote in message
...
Hi Mark,
Typically just after loading a template the activesheet would be the first
sheet in the template, ie first tab, though not necessarily depending on
how
the template was saved.
change
'Set oWs = oExcelApp.ActiveWorkSheet
to
Set oWs = oExcelApp.ActiveSheet
Note Activesheet could also be a Chart sheet
Regards,
Peter T
"MP" wrote in message
...
Hi
Trying to learn automating excel via vba
Dim oWb as Workbook
Set oWb = oExcelApp.WorkBooks.Add (TEMPLATE_NAME)
'that works
Dim oWs as WorkSheet
Set oWs = oWb.Worksheets.Item(1)
'That works
so the above line is ok but I thought maybe this would be a "better" way
I assumed a new workbook would begin with the first sheet activated???
'Set oWs = oExcelApp.ActiveWorkSheet
'but it throws error (Object doesn't support this property or method)
What is the proper way to get the first sheet in a new workbook?
Thanks
Mark
|