Set a reference to another workbook

nigelk

Well-known Member
Joined
Aug 30, 2008
Messages
537
Hi all

I have the following code

Code:
Workbooks.Open FileName:="C:\Sports\Golf.xlsm"

which works fine, however, as the the workbook is already open all I want to do is set a reference to it so I can write to it later. This gives a "Subcript out of range" error (Sportbook is dimmed as a workbook)

Code:
  Set Sportbook = Application.Workbooks("C:\Sports\Golf.xlsm")


What am I doing wrong?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
HTH. Dave
Code:
Dim Ofsobj As Object, NewWb As Object
Set Ofsobj = CreateObject("Scripting.FileSystemObject")
Set NewWb = Ofsobj.GetFile("C:\Sports\Golf.xlsm")
Workbooks.Open Filename:=NewWb
'to use example
Workbooks(NewWb.Name).Sheets("sheet1").Cells(1, "A").Value = _
          ThisWorkbook.Sheets("sheet1").Cells(1, "A").Value
Set NewWb = Nothing
Set Ofsobj = Nothing
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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