Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
When a user saves a workbook, you can not trust the user to save while
residing in a preferred sheet. Nor can you trust that the sheets will always have the same name as the previous workbook. I need some code that will move my VB process to the first sheet, or leftmost, sheet in the workbook. Something along the lines of; Activesheet.Next.Select or Activesheet.Previous.Select but the problem is, I don't know how many sheets could possiblely be in the workbook or what sheet the cursor was on when the workbook was last saved. Any suggestions? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Worksheets(1).Activate
-- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Whicks" wrote in message ... When a user saves a workbook, you can not trust the user to save while residing in a preferred sheet. Nor can you trust that the sheets will always have the same name as the previous workbook. I need some code that will move my VB process to the first sheet, or leftmost, sheet in the workbook. Something along the lines of; Activesheet.Next.Select or Activesheet.Previous.Select but the problem is, I don't know how many sheets could possiblely be in the workbook or what sheet the cursor was on when the workbook was last saved. Any suggestions? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try executing this...
Sheets(1).Select Rick "Whicks" wrote in message ... When a user saves a workbook, you can not trust the user to save while residing in a preferred sheet. Nor can you trust that the sheets will always have the same name as the previous workbook. I need some code that will move my VB process to the first sheet, or leftmost, sheet in the workbook. Something along the lines of; Activesheet.Next.Select or Activesheet.Previous.Select but the problem is, I don't know how many sheets could possiblely be in the workbook or what sheet the cursor was on when the workbook was last saved. Any suggestions? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Whicks" wrote in message
... When a user saves a workbook, you can not trust the user to save while residing in a preferred sheet. Nor can you trust that the sheets will always have the same name as the previous workbook. I need some code that will move my VB process to the first sheet, or leftmost, sheet in the workbook. And I take it you're doing something to prevent the user from re-arranging the sheets...? |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Bob & Rick,
I seem to have something a bit odd going on here. Was about to post same as you guys, thought I'd better check for typos and it failed, but not due to a typo Worksheets(1).Activate ' fail Sheets(1).Select' fail ActiveWorkbook.Worksheets(1).Select ' fail Debug.Print Err.Number ' 40036 Debug.Print Err.Description ' Application-defined or object-defined error ' same error on all above Debug.Print Worksheets.Count ' 5 But this worked Dim ws as Worksheet Set ws = Worksheets(1) ws.Activate I then tried the code that failed on a some other wb's and all three lines worked, as expected. FWIW I've been running some tests filling the book with up to 2 million cells of dummy data. Currently it's unsaved, ie the wb that won't accept the sheet activate code. Any thoughts ? Regards, Peter T "Rick Rothstein (MVP - VB)" wrote in message ... Try executing this... Sheets(1).Select Rick "Whicks" wrote in message ... When a user saves a workbook, you can not trust the user to save while residing in a preferred sheet. Nor can you trust that the sheets will always have the same name as the previous workbook. I need some code that will move my VB process to the first sheet, or leftmost, sheet in the workbook. Something along the lines of; Activesheet.Next.Select or Activesheet.Previous.Select but the problem is, I don't know how many sheets could possiblely be in the workbook or what sheet the cursor was on when the workbook was last saved. Any suggestions? |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
OMG! I was tremendously over thinking this! I was writing something
that would count the sheets and so on... Thank You! |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Apr 24, 3:25*pm, "Jeff Johnson" wrote:
"Whicks" wrote in message ... When a user saves a workbook, you can not trust the user to save while residing in a preferred sheet. *Nor can you trust that the sheets will always have the same name as the previous workbook. *I need some code that will move my VB process to the first sheet, or leftmost, sheet in the workbook. And I take it you're doing something to prevent the user from re-arranging the sheets...? No. This is for a user who pulls down a global report from "X" system. Then said person wants to isolate "Z" population. I am providing a macro that will breakdown the report using access. I just want the user to not have to worry about what page they save on. Just save in this folder and hit go. If it's universal, it will sell. |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Apr 24, 3:33*pm, Whicks wrote:
On Apr 24, 3:25*pm, "Jeff Johnson" wrote: "Whicks" wrote in message ... When a user saves a workbook, you can not trust the user to save while residing in a preferred sheet. *Nor can you trust that the sheets will always have the same name as the previous workbook. *I need some code that will move my VB process to the first sheet, or leftmost, sheet in the workbook. And I take it you're doing something to prevent the user from re-arranging the sheets...? No. *This is for a user who pulls down a global report from "X" system. *Then said person wants to isolate "Z" population. *I am providing a macro that will breakdown the report using access. *I just want the user to not have to worry about what page they save on. *Just save in this folder and hit go. *If it's universal, it will sell. Between your post Jeff and then me thinking about the "If it's universal, it will sell.", I finally see your point. Hmmmm...how do you suppose I ensure each sheet is correct? Without protecting the workbook. 1) We can not trust the sheets to be named correctly 2) We can not trust the sheets to be in the proper location 3) Each sheet contains like data |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
OK understood. In the Sheet1 module I had an API declared like this -
Declare Function etc ' ie public After commenting it or changing it to Private Declare Function etc the other rudimentary code worked fine, ie simply Worksheets(1). etc I know very well not to declare a function as public in an object module, only came about due to helping in another recent thread today. It's now clear why the code failed, curious though that it worked after doing this - Dim ws as Worksheet set ws = Worksheets(1) Regards, Peter T "Peter T" <peter_t@discussions wrote in message ... Bob & Rick, I seem to have something a bit odd going on here. Was about to post same as you guys, thought I'd better check for typos and it failed, but not due to a typo Worksheets(1).Activate ' fail Sheets(1).Select' fail ActiveWorkbook.Worksheets(1).Select ' fail Debug.Print Err.Number ' 40036 Debug.Print Err.Description ' Application-defined or object-defined error ' same error on all above Debug.Print Worksheets.Count ' 5 But this worked Dim ws as Worksheet Set ws = Worksheets(1) ws.Activate I then tried the code that failed on a some other wb's and all three lines worked, as expected. FWIW I've been running some tests filling the book with up to 2 million cells of dummy data. Currently it's unsaved, ie the wb that won't accept the sheet activate code. Any thoughts ? Regards, Peter T "Rick Rothstein (MVP - VB)" wrote in message ... Try executing this... Sheets(1).Select Rick "Whicks" wrote in message ... When a user saves a workbook, you can not trust the user to save while residing in a preferred sheet. Nor can you trust that the sheets will always have the same name as the previous workbook. I need some code that will move my VB process to the first sheet, or leftmost, sheet in the workbook. Something along the lines of; Activesheet.Next.Select or Activesheet.Previous.Select but the problem is, I don't know how many sheets could possiblely be in the workbook or what sheet the cursor was on when the workbook was last saved. Any suggestions? |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You can work with the sheet codename, the user won't change that, maybe have
an index as part of the name, and then sort them on opening/closing. -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Whicks" wrote in message ... On Apr 24, 3:33 pm, Whicks wrote: On Apr 24, 3:25 pm, "Jeff Johnson" wrote: "Whicks" wrote in message ... When a user saves a workbook, you can not trust the user to save while residing in a preferred sheet. Nor can you trust that the sheets will always have the same name as the previous workbook. I need some code that will move my VB process to the first sheet, or leftmost, sheet in the workbook. And I take it you're doing something to prevent the user from re-arranging the sheets...? No. This is for a user who pulls down a global report from "X" system. Then said person wants to isolate "Z" population. I am providing a macro that will breakdown the report using access. I just want the user to not have to worry about what page they save on. Just save in this folder and hit go. If it's universal, it will sell. Between your post Jeff and then me thinking about the "If it's universal, it will sell.", I finally see your point. Hmmmm...how do you suppose I ensure each sheet is correct? Without protecting the workbook. 1) We can not trust the sheets to be named correctly 2) We can not trust the sheets to be in the proper location 3) Each sheet contains like data |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Whicks" wrote in message
... Hmmmm...how do you suppose I ensure each sheet is correct? Without protecting the workbook. 1) We can not trust the sheets to be named correctly 2) We can not trust the sheets to be in the proper location 3) Each sheet contains like data Honestly, I still don't understand what you're trying to do. Can you give me a real-world, detailed scenario instead of using generic terms? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Select number from leftmost column that has one | Excel Discussion (Misc queries) | |||
leftmost number value | Excel Discussion (Misc queries) | |||
vlookup- is a must that lookup value should be the leftmost colum? | Excel Discussion (Misc queries) | |||
Delete rows with specific leftmost value | Excel Programming | |||
Leftmost and Rightmost Cell | Excel Programming |