If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Getting data from closed books with VBA

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-06-05, 10:21
michaeldavid michaeldavid is offline
Registered User
 
Join Date: Dec 2004
Posts: 35
Getting data from closed books with VBA

This one may be a bit tricky, but I am hoping someone will know the answer.
I have used this Function that I got from a book to retrive values from closed books with VBA

Function GetValue(Path, File, Sheet, ref)
Dim Arg As String
Arg = "'" & Path & "[" & File & "]" & Sheet & "'!" & Range(ref).Address(, , xlR1C1)
GetValue = ExecuteExcel4Macro(Arg)
End Function

It is basically building the formula for a lined cell, but when getting values in VBA it saves me having to open the book get the value and then close the book again. I would use a procedure like the one below to get it to pass back the value

sub GetData
dim dummy
dummy = getvalue("C:\work\","Accounts.xls","2005","A1")
end sub

What I would like to be able to do is pass it the row and column numbers rather than "A1"

Hence dummy = getvalue("C:\work\","Accounts.xls","2005",1,1)
would give me the same answer

Does anyone know what the "& Range(ref).Address(, , xlR1C1)" part of the function would need to be in order to accomplish this? Any help would be very much appreciated.
Reply With Quote
  #2 (permalink)  
Old 01-06-05, 10:33
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
or you could change
Function GetValue(Path, File, Sheet, ref)

to Function GetValue(Path, File, Sheet, refRow, RefCol)

Then Change Range(ref).Address(, , xlR1C1) to
cells(refRow,RefCol).Address(, , xlR1C1)

Is that what your after

Dave
Reply With Quote
  #3 (permalink)  
Old 01-06-05, 12:43
michaeldavid michaeldavid is offline
Registered User
 
Join Date: Dec 2004
Posts: 35
Many thanks David.

This little tip has saved me hours/days of trial and error

Michael
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On