VBA: Moving Sheets: Variable Names

BluRayBoy

New Member
Joined
May 7, 2010
Messages
2
Hi,

Having cobbled together the following I'm snagged on how to move a sheet in the active workbook to another open workbook which I do not want to explicitly type the name of.

'Move sheet to target book
ActiveSheet.Move Before:=Workbooks(XXX).Sheets(1)

Where XXX on other forums can be substituted for "filename.xls", I want to be able to define a variable to use there. The reason is elsewhere in the code I use this:

sFileName = Application.GetOpenFilename

to choose a file, then this:

Me.TextBox2.Value = sFileName

to display it in a text box. I then open the file displayed in textbox2.

I want to make it so that I can replace XXX with the filename in TextBox2 and have the macro copy the active sheet to it!

Thanks in advance.

Tom
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

BluRayBoy

New Member
Joined
May 7, 2010
Messages
2
I have tried doing this:

Dim Target As String
Target = Me.TextBox2.Value

and forcing 'Target' in to the space where XXX is but a)not sure if it works at all and b) not sure how to format it.

Cheers!
 

Forum statistics

Threads
1,136,780
Messages
5,677,688
Members
419,712
Latest member
LearningCR

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
Top