I get an Error 58, HELP!

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
I am trying to move a file I used earlier into the newly created path.




I get an error 58. It says the file already exists? It does not!! Here is a long line of code:
Code:
Sub Save_To_Client()


Dim strfilename As String, strPath As String, strPath2 As String, CurrPath As String, foldName As String, MyVal As String
Dim MyPath As String, MyPathExtended As String, strClientName As String, strPdfName As String, strName2Clients As String
Dim wsDest As Worksheet, strEstimateName As String

    Dim WB1 As Workbook
    Dim WB2 As Workbook
    Dim fso, Estfile As String, sfol As String, dfol As String
    Application.ScreenUpdating = False
    
    Set WB1 = ActiveWorkbook
    
    'First thing, save my work
    WB1.Save
    
    CurrPath = WB1.Path
    
    strfilename = Range("S16").Value & ".xlsm"
    
    strPdfName = Range("S16").Value & ".pdf"
    
    strPath = "C:\Documents and Settings\Owner\Desktop\Clients\"
    
    strPath2 = "C:\Documents and Settings\Owner\My Documents\Surface Systems\"
    
    foldName = Trim(Range("S15"))
    
    MyVal = Range("T10").Value
    
    strClientName = Range("S17").Value
    
    strName2Clients = Range("U5").Value
    
    
    
'    On Error Resume Next
    
    Set wsDest = WB1.Worksheets("EstimatingData")
    wsDest.Range("A1").Value = RipIllegals(wsDest.Range("A1"))
    wsDest.Range("N1").Value = RipIllegals(wsDest.Range("N1"))
      
    
    MyPath = "C:\Documents and Settings\Owner\Desktop\Clients\" & MyVal & "\" & strClientName
    If Len(Dir(MyPath, vbDirectory)) = 0 Then
            MkDir MyPath
        End If
    MyPathExtended = MyPath & "\" & foldName
    If Len(Dir(MyPathExtended, vbDirectory)) = 0 Then
            MkDir MyPathExtended
    End If
    Select Case MyVal
        Case vbNullString   'Company name missing
            Exit Sub
        Case "a" To "z"     'This is alphabetic
            ActiveWorkbook.SaveAs MyPathExtended & "\" & strfilename
                    Estfile = Range("U10").Value ' change to match the file name
                    sfol = "C:\Documents and Settings\Owner\Desktop\Clients\" ' change to match the source folder path
                    dfol = MyPathExtended ' change to match the destination folder path
                Set fso = CreateObject("Scripting.FileSystemObject")
                    If Not fso.FileExists(sfol & Estfile) Then
                        MsgBox sfol & Estfile & " does not exist!", vbExclamation, "Source File Missing"
                    ElseIf Not fso.FileExists(dfol & Estfile) Then
                        fso.MoveFile (sfol & Estfile), dfol  '*******
                    Else
                        MsgBox dfol & Estfile & " already exists!", vbExclamation, "Destination File Exists"
                    End If
        Case Else           'This is other
            ActiveWorkbook.SaveAs strPath & "Other" & "\" & strClientName & "\" & foldName & "\" & strfilename   ', xlNormal
    End Select
    
    Set WB2 = Workbooks.Open(Filename:=strPath2 & "Proposal for XL.xlsm") 'Open "Proposal for XL"
        
    
        
        
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    MyPathExtended & "\" & strPdfName, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    False
    
    On Error GoTo 0
    
    ChDir CurrPath
    
    Application.ScreenUpdating = True
    
    WB1.Close
       
       
       
End Sub

Errors out on this line:
Code:
fso.MoveFile (sfol & Estfile), dfol  '**********


Any help is greatly appreciated,
Michael
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Michael

Are you absolutely sure it doesn't exist?

Are you actually checking for it in the right folder?

Things can get tricky when you use 'special folders' like 'Documents and Settings'.

I have enough problems locating my own 'My Documents' folder.:)
 
Upvote 0
Change the folder location to somewhere else and rerun it. If it works then the folder was correct in reporting it the file exists.
 
Upvote 0
:)
Special-K99,
That was perfect!! It was in fact the "\" afterward. Well, at least as soon as i added it, it worked.
Thank you for the quick responses today also. This was a life saver!!


Thank You,
Michael
 
Upvote 0

Forum statistics

Threads
1,223,520
Messages
6,172,811
Members
452,481
Latest member
Najwan

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