Mike Magill
New Member
I have a template that once opened as a new worksheet asks the user to provide the path to their SharePoint document library - the workbook should then saved to that location.
If the user provides a valid URL first time, the SaveAs command works perfectly. However, if the user provides a spurious URL, I have some error trapping that asks them to re-enter. My code first of all tries to save to the spurious location and if it fails resets the error code and repeats the user request. If they enter the location correctly second time around the SaveAs routine still throws up an error! It seems the workbook's fullname has been set to the spurious URL despite the save failing.
Rather than share all the code I've built a short routine below that demos the problem. When run (using a proper SharePoint address) the second SaveAs fails. If, however. you comment out the first SaveAs the second SaveAs works! I'm stumped. Can anyone shed any light?
If the user provides a valid URL first time, the SaveAs command works perfectly. However, if the user provides a spurious URL, I have some error trapping that asks them to re-enter. My code first of all tries to save to the spurious location and if it fails resets the error code and repeats the user request. If they enter the location correctly second time around the SaveAs routine still throws up an error! It seems the workbook's fullname has been set to the spurious URL despite the save failing.
Rather than share all the code I've built a short routine below that demos the problem. When run (using a proper SharePoint address) the second SaveAs fails. If, however. you comment out the first SaveAs the second SaveAs works! I'm stumped. Can anyone shed any light?
Code:
Sub FirstTimeSave1()
Dim Path1 As String
Dim Path2 As String
Dim FileSaveName As String
Path1 = "http://bbc.co.uk/"
Path2 = "Replace with URL to SharePoint document library"
On Error Resume Next
ThisWorkbook.SaveAs Filename:=Path1 & FileSaveName _
, FileFormat:=52, CreateBackup:=False
If Err.Number <> 0 Then
Err.Clear
MsgBox "Despite not saving, the workbook's full name is now: " & ThisWorkbook.FullName
Else
Exit Sub
End If
ThisWorkbook.SaveAs Filename:=Path2 & FileSaveName _
, FileFormat:=52, CreateBackup:=False
If Err.Number <> 0 Then
Err.Clear
MsgBox "Valid second path not saved. The workbook's full name is still: " & ThisWorkbook.FullName
End If
End Sub