[VBA] How to handle errors when adressing multiple sheets

NessPJ

Active Member
Joined
May 10, 2011
Messages
422
Office Version
  1. 365
Hi,

I am currently working on an Excel sheet with VBA that also opens a few other files in the routine etc.

Now i was working on creating an ErrorHandler for the file but i ran into a problem where my "OriginalWorkbook" was no longer
activated because i opened "WorkbookX" and an error would occur.

What would be my best way for the ErrorHandler to safely check/handle Activating the "OriginalWorkbook" and or even closing "WorkbookX" ?

If i use the following construction inside the ErrorHandler when it is called, RTBook could actually be the name of "WorkbookX" instead of "OriginalWorkbook".

RTBook = ActiveWorkbook.Name

Application.Workbooks(RTBook).Activate

Eg. The filename for "OriginalWorkbook" is not a constant and changes on a weekly basis (otherwise i could declare it as a Public Constant).

Is there something like a Public Variable i can use or something?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
'ThisWorkbook' is the workbook where the running VBA code is housed. That should help.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top