ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ExecuteExcel4Macro Error (https://www.excelbanter.com/excel-programming/416238-executeexcel4macro-error.html)

anon

ExecuteExcel4Macro Error
 
Hi all,

For the first time today I have come across the GetValue function. I
am looking to get values from a (very large) workbook and would prefer
to do it without opening the other wb as it takes up to 3 mins to
open. I also cannot use any method that requires setting a reference
as my workbook is distributed to users running many different versions
of Excel - therefore GetValue seemed a simple and suitable solution.

My code is below;

sub getthevalues
'other code defining pathrr and mypath
p = pathrr
f = mypath
s = "SVRed.xls"
a = "B11"
MsgBox GetValue(p, f, s, a)
end sub


Function GetValue(Path, File, Sheet, Ref)
'Retrieves a value from a closed workbook
Dim Arg As String
'Make sure the file exists
If Right(p, 1) < "\" Then Path = p & "\"
If Dir(Path & f) = "" Then
GetValue = "File not Found"
Exit Function
End If
'Create the argument
Arg = "'" & p & "[" & f & "]" & s & "'!" &
Range(Ref).Range(a).Address(, , xlR1C1)
'Execute XLM macro
MsgBox (Arg)
On Error Resume Next
GetValue = ExecuteExcel4Macro(Arg)
End Function


This errors on;
GetValue = ExecuteExcel4Macro(Arg)

I have checked and re-checked the Arg string and this is definately
correct. I can't seem to find much information about what
ExecuteExcel4Macro is or does and therefore am stumped! I would
appreciate any help or simply explanations.

Thanks



ytayta555

ExecuteExcel4Macro Error
 
On 28 Aug, 21:22, anon wrote:
My code is below;


Function GetValue(Path, File, Sheet, Ref)
* * *'Retrieves a value from a closed workbook
* * Dim Arg As String
* * 'Make sure the file exists
* * If Right(p, 1) < "\" Then Path = p & "\"

.......................... ....... .....
* * MsgBox (Arg)
* * On Error Resume Next
GetValue = ExecuteExcel4Macro(Arg)
End Function

This errors on;
GetValue = ExecuteExcel4Macro(Arg)


Just an idea , maybe you need an If ...Then before
this line of code : GetValue = ExecuteExcel4Macro(Arg)


ytayta555

ExecuteExcel4Macro Error
 
You wrote so :
* * *'Execute XLM macro


* * MsgBox (Arg)
* * On Error Resume Next
GetValue = ExecuteExcel4Macro(Arg)
End Function


Ask :
,,ExecuteExcel4Macro(Arg),, is a name of a macro ?

Do you want to Call (Run) a macro from this function ?


All times are GMT +1. The time now is 05:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com