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:
Errors out on this line:
Any help is greatly appreciated,
Michael
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