Using the Getvalue Function & ExecuteExcel4Macro

Joined
Jul 12, 2005
Messages
6
Reaction score
0
Hi! I am needing to pull information from multiple workbooks and have found code from John in one of the EEE newsletters about the GetValue Function that uses ExecuteExcel4Macro.

Now I know nothing about ExecuteExcel4Macro, but this was his code for the GetValue Function taken from: http://j-walk.com/ss/excel/eee/eee009.txt

From John:

The GetValue function, listed below takes four arguments:


path: The drive and path to the closed file (e.g., "d:\files")
file: The workbook name (e.g., "99budget.xls")
sheet: The worksheet name (e.g., "Sheet1")
ref: The cell reference (e.g., "C4")


Private Function GetValue(path, file, sheet, range_ref)

' Retrieves a value from a closed workbook

Dim arg As String

' Make sure the file exists

If Right(path, 1) <> "\" Then path = path & "\"

If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If

' Create the argument

arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(range_ref).Range("A1").Address(, , xlR1C1)

' Execute an XLM macro

GetValue = ExecuteExcel4Macro(arg)

End Function


Ok so my question is this, the worksheets in each work book are named differently but all still have the code name of Sheet1. I was wondering if there is a way to use the code name instead of the user defined sheet name? Thanks for you help!!
 

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