I assume you are using variables to hold the workbook and/or worksheet name. This will work for you (assumes variables named ThisWorkbook and ThisSheet).
ThisWorkbook = ActiveWorkbook.Name
ThisWorksheet = ActiveSheet.Name
Regards,
Barrie
Mindy, Collect the Activeworkbook.name and Activesheet.name in variables before your macro changes the activebook or sheet.
[EXAMPLE]
sub myMacro
dim sMyBook as String
dim sMySheet as String
'FIRST THING - Collect the book and sheet names
sMyBook = Activeworkbook.name
sMySheet = Activesheet.name
'The rest of your code
'If you want to go back to the original book and sheet
Workbooks(sMyBook).activate
Worksheets(sMySheet).activate
end sub
Hope this helps, Jerid
Occur on only onkey function
I actually keep the workbook name in the variable.
However, I have two procedure to execute the macro.
One will be executed when the workbook_open. This is one is fine.
The other one to execute the same macro is when F5 press, which is where it loose the original workbook name.
Is that matter where I set the Application.onKey function? Even I place the assigning workbook name at the procedure where the onKey function called, it still keep lossing the name.
Any idea of what do I do wrong?
Thank you very much
Mindy
Re: Occur on only onkey function
Mindy, Are you storing the Activeworkbook.Name in a Public Variable? Are you getting any error messages? Are you using Excel97?
There is a bug in Excel97, that if you have a runtime error you lose all Public variables.
A sample of your code might help us help you.
Jerid