PDA

View Full Version : [SOLVED:] Run time error 52 - bad file name or number



megha
07-28-2014, 09:36 AM
Can someone please help me with this error message? I am using the following code:



Private Sub CommandButton2_Click()
Dim sFileName As String
Dim sPath As String
CommandButton2.Enabled = False
sFileName = Format(DateValue(Now()), "mmm_dd_yyyy") & "_" & _
Format(TimeSerial(Hour(Now()), Minute(Now()), Second(Now())), "hh_mm_ss_AM/PM")
If Len(Dir("\\refining.sp.sabert.net/sites/op/olt/Production Supervisors/HouseKeeping/Completed_Checklist\" & Format(DateValue(Now()), "mmm_yyyy"), vbDirectory)) = 0 Then
MkDir "\\refining.sp.sabert.net/sites/op/olt/Production Supervisors/HouseKeeping/Completed_Checklist\" & Format(DateValue(Now()), "mmm_yyyy")
End If
sPath = "\\refining.sp.sabert.net/sites/op/olt/Production Supervisors/HouseKeeping/Completed_Checklist\" & Format(DateValue(Now()), "mmm_yyyy")
sFileName = sFileName & "_" & Unit.Value & "_" & ID.Value & "_" & Worksheets("Housekeeping Inspection Sheet").Range("I43").Value & ".xlsm"

ActiveWorkbook.SaveAs Filename:=sPath & "\" & sFileName, FileFormat:=52, ReadOnlyRecommended:=False
ThisWorkbook.Close SaveChanges:=False
End Sub

megha
07-28-2014, 10:06 AM
I figured it out..Thanks!