Opening workbook based on cell input

JohnKGH

New Member
Joined
Jul 1, 2011
Messages
7
Hey guys,

I am trying to write a macro that opens a workbook based on cell input from the current workbook.

Worksheets("Options Selector").Select

Name1 = Range("C19").Value

Name2 = Range("C18").Value

Workbook_name = """" & Name1 & "_" & Name2 & ".xls" & """"

Workbooks(Workbook_name).Worksheets("Summary").Range("B2:J33").Copy

But I get a subscript out of range error on the last line. It's because it's not accessing workbooks(workbook_name). Workbook_name should be "name1_name2.xls". I feel like i'm missing a built in VBA function to read the file and cannot just join strings like that to represent a file name.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi JohnKGH,

I believe the problem is that your code makes the quotes part of the workbook name. All you should need is:

Workbook_name = Name1 & "_" & Name2 & ".xls"

Keep Excelling.

Damon
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,391
Members
452,909
Latest member
VickiS

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