Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make worksheet from another file the Active sheet

Status
Not open for further replies.

AccessVB

MIS
Joined
Jun 23, 2002
Messages
82
Location
US
Can anyone tell me how through VB I can make a worksheet from another file the active sheet when I am executing code on a file. What I need to do say grab the value in cell A1 from another file's worksheet and paste it in my current file.
 
AccessVB,

You do not necessarily need to make whatever workbook/sheet active to execute code correctly.
Code:
workbooks("TheFromWorkbook.xls").worksheets("TheFromWorksheet").[A1].Copy Destination:=workbooks("TheToWorkbook.xls").worksheets("TheToWorksheet").[B5]
You can execute this code from Workbook(3).

Now its a bit cumbersome as written. If the Activesheet is the one you will copy to...
Code:
workbooks("TheFromWorkbook.xls").worksheets("TheFromWorksheet").[A1].Copy Destination:=ActiveSheet.[B5]
Since Activesheet implies the reference to the workbook that the ActiveSheet is in.

Check out this FAQ --

faq707-4105 How Can I Make My Code Run Faster?


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top