Home > Enterprise >  How to make a Macro-Free backup copy of a Word Document using VBA
How to make a Macro-Free backup copy of a Word Document using VBA

Time:10-27

I have a Macro-Enabled word document which I want to make a Macro-Free Backup Copy of my document else where on the network every time I press a certain commandbutton on my userform. I Don't want to use ".SaveAs2" because I still want to be in Macro-Enabled document after I hitting commandbutton.

In Excel we had this workaround which you could copy all sheets using "sheets.copy" on macro-enabled excel file and then save newly created workbook (which is now a macro-free workbook) anywhere you want using "ActiveWorkbook.SaveAs" method.

CodePudding user response:

Try this.

Sub Word_CopyFileBasedOnActiveDocument()
    Dim wDoc As Word.Document: Set wDoc = ActiveDocument
    Dim wTmp As Word.Document

    ' Create a new document based on the active document
    Set wTmp = Application.Documents.Add(Template:=wDoc.FullName, Visible:=False)
    
    ' Save as non macro enabled
    wTmp.SaveAs2 Filename:=wDoc.Path & "\newFile.doc", FileFormat:=wdFormatXMLDocument
    
    ' Close file
    wTmp.Close False
End Sub
  • Related