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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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!
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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