I have a macro in a document called print.doc that opens a text document then saves it as output1.doc. The 1st document then closes but output1.doc remains open. If the user thens opens print.doc again it opens the same .txt document and then saves the document as output2.doc. The problem is that when the user opens this a third time it gives me an error that word can not give a document the same name as another document. I am getting the error after an error occurs for the second time. The error handler doesn't seem to work. I don't know if this makes any sense or not but here is the code:
Private Sub Document_Open()
Documents.Open FileName:="C:\output.txt"
ChangeFileOpenDirectory "C:\"
Dim x As Integer
RetrySave:
x = x + 1
On Error GoTo RetrySave:
ActiveDocument.SaveAs FileName:="output" & x & ".doc", FileFormat:=wdFormatDocument _
, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
Windows(1).Activate
ActiveWindow.Close wdDoNotSaveChanges
End Sub
Any help will be appreciated.
Thanks,
Eric
Private Sub Document_Open()
Documents.Open FileName:="C:\output.txt"
ChangeFileOpenDirectory "C:\"
Dim x As Integer
RetrySave:
x = x + 1
On Error GoTo RetrySave:
ActiveDocument.SaveAs FileName:="output" & x & ".doc", FileFormat:=wdFormatDocument _
, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
Windows(1).Activate
ActiveWindow.Close wdDoNotSaveChanges
End Sub
Any help will be appreciated.
Thanks,
Eric