picking an active workbook

Debo333

New Member
Joined
Oct 18, 2006
Messages
11
Hi there,

I have a form with the first line of code as

ActiveWorkbook.Sheets("sheetX").Activate

shere sheetx is a sheet in the workbook containing the forms. If another workbook is open and selected when the command ok button is clicked I get an error obviously because the current active workbook does not contain sheet x. I am trying to write in code that either selects the workbook containing the forms such as activeworkbook.select "filename C:/workbookx.xls", or embeds the forms into their respective sheets inside the workbook containing the forms. Please let me know if either of those options is possible and thank you for your time.
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

rabarnes

New Member
Joined
Sep 7, 2006
Messages
26
ActiveWorkbook does exactly what it says, looks for the sheet within the active workbook. You therefore first need to select the workbook you require. Try:

Workbooks("workbookx").Activate
Sheets("sheetx").Select

Hope that's what you're looking for?

Rowan
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,915
Office Version
  1. 365
Platform
  1. Windows
What you could use also is ThisWorkbook.

That would refer to whatever workbook the code was in.
Code:
ThisWorkbook.Sheets("sheetx").Select
By the way why are you selecting the sheet?
 

Watch MrExcel Video

Forum statistics

Threads
1,113,915
Messages
5,545,016
Members
410,646
Latest member
LegenDSlayeR
Top