Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Unable to change ActiveSheet within Workbook_Open

I'm trying to modify a macro that I inherited. This .xls (created as
a 2003 .xls but run under 2007) has a Workbook_Open macro that
automatically runs when the .xls is opened. The macro opens a .csv
file and then tries to make this .csv file the active sheet but it
seems that the active sheet can't be changed to this .csv file and the
active sheet remains as the original active sheet when the .xls was
initially opened. Here's the code fragment:

Sub Workbook_Open()
Workbooks.Open dailystart ' open the .csv file
Set wbdata = ActiveWorkbook
MsgBox ActiveWorkbook.Name
MsgBox ActiveSheet.Name
Range(Cells(2, 1), Cells(1, 1).End(xlDown)).NumberFormat = "mm/dd/
yy;@"

' explicitly activate the .csv workbook and sheet
wbdata.Activate
wbdata.Sheets(1).Activate
wbdata.Sheets(1).Select
wbdata.Sheets(1).Name = "Summary"
MsgBox ActiveWorkbook.Name
MsgBox ActiveSheet.Name

I would expect that the active workbook and sheet would change to
the .csv file (with it's single sheet) when it is opened. The above
MsgBox's show the active workbook is the .csv file but the active
sheet remains as the original active sheet. However, the NumberFormat
statement applies to the .csv file which suggests that the .csv file
is the active sheet.

Then the macro tries explicitly activate the just opened .csv file.
It successfully changes the name of the .csv file single sheet and the
active workbook is correct but the active sheet remains the original
sheet of the .xls of the Workbook_Open.

Can someone explain what is going on? Is there something special
about trying to change the active sheet from within a Workbook_Open
macro?

Denis


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Unable to change ActiveSheet within Workbook_Open

Can someone explain what is going on? Is there something special
about trying to change the active sheet from within a Workbook_Open
macro?


Quite a few things in a workbook's open event are best deferred until the
workbook is fully open. Call your CSV stuff in an ontime macro, eg

' in the open event
Application.OnTime Now, "OpenCSV"

where Sub OpenCSV() is in a normal module with code to op[en the CSV etc

Regards,
Peter T

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Unable to change ActiveSheet within Workbook_Open

On Jun 23, 11:00*am, "Peter T" wrote:
Can someone explain what is going on? *Is there something special
about trying to change the active sheet from within a Workbook_Open
macro?


Quite a few things in a workbook's open event are best deferred until the
workbook is fully open. Call your CSV stuff in an ontime macro, eg

' in the open event
Application.OnTime Now, "OpenCSV"

where Sub OpenCSV() is in a normal module with code to op[en the CSV etc

Regards,
Peter T


Yes, Application.OnTime Now works much better. Thanks.

Denis
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to change office assistant Nikky Excel Discussion (Misc queries) 1 January 22nd 09 12:10 PM
Use a password in VBA ActiveSheet.protect & ActiveSheet.unprotect? Jim K. Excel Programming 2 June 2nd 08 08:09 PM
Unable to change tab color pro Excel Worksheet Functions 0 April 30th 08 06:34 PM
Unable to change NumberFormat Property Geoff Excel Programming 2 February 12th 07 12:36 AM
Copying new activesheet after other activesheet is hidden? Simon Lloyd[_790_] Excel Programming 1 June 20th 06 10:02 AM


All times are GMT +1. The time now is 01:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"