Error 2023 while retrieving data from a closed workbook

rbakhtiar

New Member
Joined
Sep 17, 2006
Messages
8
i have two codes: Function and Sub (copied from john walkenbach's power programming with vba pp 328-9). i am a novice to vba.

the routine gives an error message 2023 and fills the destination range with #Ref!

kindly help.

------------------------------------------------

Private Function GetValue(path, file, ref)
Dim arg As String
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = " " Then
GetValue = "File Not Found"
Exit Function
End If

arg = "'" & path & "[" & file & "]" & "'!" & _
Range(ref).Address(, , xlR1C1)
GetValue = ExecuteExcel4Macro(arg)
End Function

--------------------------------------------------------------
Sub GetValue2()

p = "G:\Common\Bakhtiar\GBI"
f = "GBI_COMP_ADIA_20010101.csv"

Application.ScreenUpdating = False

For r = 1 To 100
For c = 1 To 5
a = Cells(r, c).Address
Cells(r, c) = GetValue(p, f, a)
Next c
Next r

Application.ScreenUpdating = True
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi

Does it work with a normal xls file? If so, I suspect it is because you are using it on a csv file (which is a text file).

Richard
 

Forum statistics

Threads
1,136,618
Messages
5,676,844
Members
419,655
Latest member
pd2021vb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top