VBA Reference other workbook

dturgel

Board Regular
Joined
Aug 6, 2015
Messages
58
Hi,

I'm moving a pricing worksheet from inside my workbook to an external workbook. I have the following lines of code that I want to turn into a reference from internal to external. I know the general idea is to use [external]! format but every time I have tried to do that in the past in VBA I've failed. Can someone please help me out here?

Sheets("Mkt curve").Select
ActiveWorkbook.Worksheets("Mkt curve").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Mkt curve").Sort.SortFields.Add
ActiveWorkbook.Worksheets("Mkt curve").Sort
ActiveCell.FormulaR1C1 = "='Mkt curve'!R[-4]C[155]"


Is it as simple as just turning them into the following?

Sheets([2012-2016 bound and quoted register]"Mkt curve").Select
ActiveWorkbook.Worksheets([2012-2016 bound and quoted register]"Mkt curve").Sort.SortFields.Clear
ActiveWorkbook.Worksheets([2012-2016 bound and quoted register]"Mkt curve").Sort.SortFields.Add
ActiveWorkbook.Worksheets([2012-2016 bound and quoted register]"Mkt curve").Sort
ActiveCell.FormulaR1C1 = "='[2012-2016 bound and quoted register]Mkt curve'!R[-4]C[155]"

I feel like I'm missing something.

Thanks!

Daniel
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
[external]! only works in sheets. For VBA, you need something like:

WorkBooks("MyBookName").Sheets("MySheetName").Select
 
Upvote 0
yky, thanks!

I tried the code but when the macro ran it tripped over the following line - does anything look wrong to you in how I applied this to my specific workbooks/sheets?

Workbooks("2012-2016 bound and quoted register").Sheets("Mkt curve").Select

Daniel
 
Upvote 0
Try adding extension, most likely ".xlsx" or ".xlsm", to the name of the workbook. You need to use the full name, including extension, of the file.
 
Upvote 0

Forum statistics

Threads
1,215,515
Messages
6,125,279
Members
449,220
Latest member
Excel Master

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