D
dsc
The following code has a problem:
OnError GoTo Handler
(snip)
TryAgain:
DirString = ActiveDocument.Variables("CompanyName").Value
MyDocLocation = "C:\My Documents\" & DirString & "\" & NameString
CheckString = "C:\My Documents\" & DirString
PathExists = Len(VBA.Dir(PathName:=CheckString, Attributes:=vbDirectory))
Err.Clear
If Not PathExists = 0 Then
ActiveDocument.SaveAs FileName:=MyDocLocation
Else
SaveHere = MyDocLocation
With SaveWorkingFileForm
SaveWorkingFileForm.TextBox1.Text = MyDocPath
SaveWorkingFileForm.TextBox1.SelStart = 0
SaveWorkingFileForm.TextBox1.SelLength =
Len(SaveWorkingFileForm.TextBox1.Text)
SaveWorkingFileForm.Show
End With
End If
Handler:
If Err.Number = 5153 Then
With SaveWorkingFileForm4
SaveWorkingFileForm4.Label2.Caption = "There is already a file
named " _
& NameString & " in directory " & CheckString & ", and it can't
be " _
& "overwritten because " _
& "it is open for editing. You must either:" & (Chr(13)) _
& "1. Give your file a different name." & (Chr(13)) _
& "2. Change the company name." & (Chr(13)) _
& "3. Cancel this macro."
SaveWorkingFileForm4.Show
GoTo TryAgain
End With
End If
Resume Next
What this is supposed to do is handle error 5153, trying to save a file with
the same name as an open file. It only kicks in where the path exists. The
line ActiveDocument.SaveAs FileName:=MyDocLocation generates error 5153,
sending us down to Handler:.
It works fine the first time through. However, if the user clicks on the
form's OK button again with the same file name in the TextBox, instead of
going to Handler: on error, it generates word's default macro error
dialogue, with its "debug" and other buttons.
Does anyone know why OnError GoTo Handler works the first time and then
stops?
All assistance gratefully received.
dsc
Yokohama
OnError GoTo Handler
(snip)
TryAgain:
DirString = ActiveDocument.Variables("CompanyName").Value
MyDocLocation = "C:\My Documents\" & DirString & "\" & NameString
CheckString = "C:\My Documents\" & DirString
PathExists = Len(VBA.Dir(PathName:=CheckString, Attributes:=vbDirectory))
Err.Clear
If Not PathExists = 0 Then
ActiveDocument.SaveAs FileName:=MyDocLocation
Else
SaveHere = MyDocLocation
With SaveWorkingFileForm
SaveWorkingFileForm.TextBox1.Text = MyDocPath
SaveWorkingFileForm.TextBox1.SelStart = 0
SaveWorkingFileForm.TextBox1.SelLength =
Len(SaveWorkingFileForm.TextBox1.Text)
SaveWorkingFileForm.Show
End With
End If
Handler:
If Err.Number = 5153 Then
With SaveWorkingFileForm4
SaveWorkingFileForm4.Label2.Caption = "There is already a file
named " _
& NameString & " in directory " & CheckString & ", and it can't
be " _
& "overwritten because " _
& "it is open for editing. You must either:" & (Chr(13)) _
& "1. Give your file a different name." & (Chr(13)) _
& "2. Change the company name." & (Chr(13)) _
& "3. Cancel this macro."
SaveWorkingFileForm4.Show
GoTo TryAgain
End With
End If
Resume Next
What this is supposed to do is handle error 5153, trying to save a file with
the same name as an open file. It only kicks in where the path exists. The
line ActiveDocument.SaveAs FileName:=MyDocLocation generates error 5153,
sending us down to Handler:.
It works fine the first time through. However, if the user clicks on the
form's OK button again with the same file name in the TextBox, instead of
going to Handler: on error, it generates word's default macro error
dialogue, with its "debug" and other buttons.
Does anyone know why OnError GoTo Handler works the first time and then
stops?
All assistance gratefully received.
dsc
Yokohama