VBA Run-time error '52' Bad file name or number help!

londoneye001

Board Regular
Joined
Sep 12, 2014
Messages
56
All,

I'm currently running an existing macro and getting this error "Run-time error '52' Bad file name or number". When i'm trying to debug the error, arrow is pointing to this statement "Open PageName For Output As #1" I'm not sure how to fix this? Appreciate help here! Below please see a full coding behind Macro if it helps!

Thanks,

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

Sub Parklane()
'
'
PageName = "\\hr\Parklane\HS\PARKLANE" & ".DAT"
FirstRow = Range("C1").Value
LastRow = Range("C2").Value


Open PageName For Output As #1
For MyRow = FirstRow To LastRow
MyStr = "" 'clear valiable
If Val(Cells(MyRow, 1).Value) > 99999999 And Val(Cells(MyRow, 1).Value) < 999999999 Then 'SIN
MyStr = MyStr & Val(Cells(MyRow, 1).Value)
Else
MyStr = MyStr & Left(Trim(Cells(MyRow, 1).Value) & String(9, " "), 9)
End If
MyStr = MyStr & "#" 'Record Identifier
Dim Dept1 As String, Dept2 As String


Dept1 = Cells(MyRow, 4).Value
Dept2 = Cells(MyRow, 5).Value

Do Until Len(Dept1) = 3
Dept1 = "0" & Dept1
Loop
Do Until Len(Dept2) = 3
Dept2 = "0" & Dept2
Loop
MyStr = MyStr & Left(Dept1 & Dept2 & String(10, " "), 10)

MyStr = MyStr & Left(Cells(MyRow, 6).Value & String(25, " "), 25) 'LastName
MyStr = MyStr & Left(Cells(MyRow, 7).Value & String(20, " "), 20) 'FirstName
MyStr = MyStr & Left(Cells(MyRow, 8).Value & String(30, " "), 30) 'Address
MyStr = MyStr & Left(Cells(MyRow, 9).Value & ", " & Cells(MyRow, 10).Value & String(30, " "), 30) 'City
MyStr = MyStr & Left(Cells(MyRow, 11).Value & String(7, " "), 7) 'PostalCode
If Val(Mid(Cells(MyRow, 12).Value, 2, 3) & Right(Cells(MyRow, 12).Value, 8)) > 999999999 Then 'AreaCode & Phone
MyStr = MyStr & Val(Mid(Cells(MyRow, 12).Value, 2, 3) & Right(Cells(MyRow, 12).Value, 8))
Else
MyStr = MyStr & String(10, " ")
End If
MyStr = MyStr & Left(Format(Cells(MyRow, 13).Value, "ddmmyyyy") & String(8, " "), 8) 'BirthDate
If Cells(MyRow, 14).Value = "Single" Then 'MaritalStatus
MyStr = MyStr & "S"
ElseIf Cells(MyRow, 14).Value = "Married" Then
MyStr = MyStr & "M"
ElseIf Cells(MyRow, 14).Value = "Divorced" Then
MyStr = MyStr & "D"
ElseIf Cells(MyRow, 14).Value = "Widowed" Then
MyStr = MyStr & "W"
ElseIf Cells(MyRow, 14).Value = "Separated" Then
MyStr = MyStr & "S"
ElseIf Cells(MyRow, 14).Value = "Common Law" Then
MyStr = MyStr & "C"
ElseIf Cells(MyRow, 14).Value = "Other" Then
MyStr = MyStr & "X"
Else
MyStr = MyStr & " "
End If
If Cells(MyRow, 15).Value = "Male" Then 'Gender
MyStr = MyStr & "M"
ElseIf Cells(MyRow, 15).Value = "Female" Then
MyStr = MyStr & "F"
End If
MyStr = MyStr & Left(Cells(MyRow, 16).Value & String(24, " "), 24) 'JobTitle
If Cells(MyRow, 17).Value = "Working" Then 'Status
Select Case Cells(MyRow, 65).Value
Case "FT"
MyStr = MyStr & "F"
Case "SS"
MyStr = MyStr & "S"
Case "PT"
MyStr = MyStr & "P"
Case "CO"
MyStr = MyStr & "C"
End Select
ElseIf Cells(MyRow, 17).Value = "Terminated - Voluntary" Then
MyStr = MyStr & "L"
ElseIf Cells(MyRow, 16).Value = "Terminated - Involuntary" Then
MyStr = MyStr & "T"
End If
MyStr = MyStr & String(296, " ")
Print #1, MyStr
Next
Close #1
'
End Sub
 

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.
Perhaps it is your path for PageName in the very first line..
 
Upvote 0

Forum statistics

Threads
1,215,515
Messages
6,125,279
Members
449,220
Latest member
Excel Master

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