Bad File Name or Number in VBA

kamisha05

New Member
Joined
Sep 25, 2015
Messages
8
Hello, I have the following code and continue to receive the run-time error #52: bad file name or number

Code:
Open FName For Input Access Read As #iF1    
    While Not EOF(iF1)
        Line Input #iF1, WholeLine
        If Right(WholeLine, 1) <> Sep Then
            WholeLine = WholeLine & Sep
        End If
        
        
        RowNdx = 2 * StarCnt + 1

When I hover over the FName, it shows the correct file that I have input, but I am not sure why it is a bad file name. It only has letters and numbers, with no special characters. What other issues could be wrong with a file name?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Is iF1 assigned? You would normally use the FreeFile function to assign the next available file number.
 
Upvote 0
Hi John, thanks for the reply. Yes, it is assigned. Here is the code right above the FName line:
Code:
    iF1 = FreeFile    RowNdx = 1
    ColNdx = 1
    StarCnt = 0
'


Open FName For Input Access Read As #iF1
    
    While Not EOF(iF1)
        Line Input #iF1, WholeLine
        If Right(WholeLine, 1) <> Sep Then
            WholeLine = WholeLine & Sep
        End If
        
        
        RowNdx = 2 * StarCnt + 1
 
Upvote 0
Also, I notice when I hover over iF1 = FreeFile, it shows iF1 = 0. So, for some reason it is not showing a value for iF1
 
Upvote 0

Forum statistics

Threads
1,215,825
Messages
6,127,111
Members
449,359
Latest member
michael2

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
Back
Top