Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Function not working correctly

I cant get the below code that calls the function (below) to work. Can
anyone tell me whats wrong with it?

'Loops through B100 to find a match
Counter = 1
Do
Counter = Counter + 1
'Calls the Closed workbook reference code to be used in
the match loop
p = "Q:\CS Management Reports\Reports Setup"
'p = "\\scgvlfs05\sesfa\CS Management Reports\Reports
Setup"
f = "Authorized List.xls"
s = "Reports Setup"
a = ("B" & Counter)
'If 5 and 3 MATCHES an Authorized ID, perform found action
RemoteValue = GetValue(p, f, s, a)
If NN = RemoteValue Then
MsgBox ("Profile " & NN & " is authorized. Click OK to
continue")
MatchFlag = 1
Exit Do

Below is the function the code above calls.

Function GetValue(path, file, sheet, 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(ref).Range("A1").Address(, , xlR1C1)

' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function


It will not work if the workbook is closed like it is
supposed to do. Why does it only work when the workbook
is open?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Function not working correctly

Actually the problem was that it wasnt working, the
problem was that it needed to have at least 1 worksheet
active in any Excel Window. Thats strange but once I
created a worksheet, it worked.


-----Original Message-----
I cant get the below code that calls the function (below)

to work. Can
anyone tell me whats wrong with it?

'Loops through B100 to find a match
Counter = 1
Do
Counter = Counter + 1
'Calls the Closed workbook reference code to be used in
the match loop
p = "Q:\CS Management Reports\Reports Setup"
'p = "\\scgvlfs05\sesfa\CS Management Reports\Reports
Setup"
f = "Authorized List.xls"
s = "Reports Setup"
a = ("B" & Counter)
'If 5 and 3 MATCHES an Authorized ID, perform found action
RemoteValue = GetValue(p, f, s, a)
If NN = RemoteValue Then
MsgBox ("Profile " & NN & " is authorized. Click OK to
continue")
MatchFlag = 1
Exit Do

Below is the function the code above calls.

Function GetValue(path, file, sheet, 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(ref).Range("A1").Address(, , xlR1C1)

' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function


It will not work if the workbook is closed like it is
supposed to do. Why does it only work when the workbook
is open?


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
If function not working correctly Relle Excel Discussion (Misc queries) 10 September 16th 09 10:42 AM
Offset function not working correctly Flipper Excel Discussion (Misc queries) 1 August 19th 09 06:45 PM
Subtotal function is not working correctly Bryan Excel Discussion (Misc queries) 0 November 21st 06 05:09 PM
Lookup function still not working correctly Mike K Excel Worksheet Functions 6 August 1st 05 02:22 AM
Sum function not working correctly in Excel (Skips Cell) Tony Excel Worksheet Functions 5 November 29th 04 11:52 PM


All times are GMT +1. The time now is 02:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"