简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM