JAMES125
asked on
VBA Code to save Word document
I'm trying to use the following code to automatically save a .docm to a .docx and then close the document. I get an error the says "The fille could not be opened because there are problems with the contents" when I try to open the saved .docx file. I assume this is because I did nto specify the format. If I change the extension to .docm it opens fine but the macros are enabled and I want to avoid this. The purpose is to strip the macros from the file and save it. Please advise.
Private Sub Document_Open()
Dim CurrentMonth, CurrentDay, CurrentYear, FileName, DocName
CurrentMonth = Left(Date, 2)
CurrentDay = Mid(Date, 4, 2)
CurrentYear = Right(Date, 4)
FileName = "C:\test" & CurrentMonth & CurrentDay & CurrentYear & ".docx"
ActiveDocument.SaveAs FileName
DocName = ActiveDocument.Name
Windows(DocName).Close wdDoNotSaveChanges
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad to be of help!