How do assign a name to a remote workbook ?

D

Dan Thompson

I am trying to have my VBA code open a workbook from a website however I
don't want to have to keep refering to the whole URL name every time I need
to call it or work with it in my code so I just want to assign a short name
variable to represent it and currently my code is giving me a subscript out
of range error here is my code

Dim WPSR As Workbook
This is the code that is not working
Set WPSR =
Workbooks("http://tonto.eia.doe.gov/oog/ftparea/wogirs/xls/psw03.xls")
Workbooks.Open WPSR


This is my original code to open the file
'Workbooks.Open
Filename:="http://tonto.eia.doe.gov/oog/ftparea/wogirs/xls/psw03.xls"
'Sheets("Data 1").Select
'ActiveWindow.SmallScroll Down:=3
 
G

Gary''s Student

Once you have opened the file (using the code that works) the name should be
available:

Dim remoteWB as string
remoteWB=ActiveWorkbook.Name
 
D

Dan Thompson

Ok That will probably work however I am looking for a way to do this without
using the ActiveWorkbook Function. For my purpose I would prefer code to
reference the remote workbook directly by its name because if I use your code
then whenever I have another workbook that is the active workbook the code
will be referencing the wrong workbook wont it ? Or dose VBA remember the
workbook name RemoteWB as the Active workbook that it first referenced at the
time you assigned RemotWB to it ?
 
G

Gary''s Student

O.K.......the trick is that when you Open a workbook, it becomes the
ActiveWorkbook.


Might as well remember its name while you are there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top