VBA question, copying a worksheet to a different workbook

aallaman

New Member
Joined
Dec 4, 2009
Messages
44
Hi Everyone,

I am a real beginner when it comes to VBA so I need your help! I am reading Mr Excel's book on VBA and Macros but I cannot find a solution to the problem below.


Any suggestions on how to do the following?
  1. The macro will be applied to an open workbook, lets call that WORKBOOK(*), as the name applies the workbook name will change between uses.
  2. One of the first steps is to open a workbook off the network that contains a reference sheet, WORKBOOK2, this I can do
  3. In WORKBOOK2 is the worksheet called REFSHEET
  4. I need to copy REFSHEET into WORKBOOK(*)
I know how to write the VBA that could copy REFSHEET from WORKBOOK2 to lets say WORKBOOK1, but then if I want to run the same code on WORKBOOK55, the code wouldn't work.

Is there a way to identify the workbook in which you start the macro as a variable, and then reference that variable in the copy worksheet code? That way the code should work no matter what WORKBOOK(*) is named.

Thanks for your help with this!!!!

Allen
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Maybe

Code:
Sheets("REFSHEET").copy after:=thisworkbook.sheets(sheets.count)
 
Upvote 0
Hey VoG,

You got me on the right track. This is what ended up working.

Sheets("Ref Sheet").Copy After:=Workbooks(ThisWorkbook).Sheets(1)

Thanks!

Allen
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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