I created a template with VBA code and userform. I saved it as .dotm (macro-enabled template).
I want to open the template, use the interface to make changes in the document and after that save the document as .docx without references to the template/code. When I open the docx and open the visual basic editor I find there the code.
This is my code to exit from the interface
Private Sub Sair_Click()
ActiveDocument.Bookmarks("NomeProj").Range.text = Nomeproj.Value
ActiveDocument.TablesOfContents(1).Update
Application.Quit
End Sub
ActiveDocument.SaveAs FileName:="Test.docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="",
AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveDocument.Convert 'Required if not Word 2007 format
Edit:
The VBA code is stored too. If you want to prevent this, the best you could do is move your text into a new document and save this document.
Simple example, based on the storage of a bookmark:
Option Explicit
Sub Save_Doc_NoMacros()
Dim ThisDoc As Word.Document
Dim oDoc As Word.Document
Set ThisDoc = ActiveDocument
ThisDoc.Bookmarks("Bookmark1").Select
Selection.Copy
Set oDoc = Documents.Add
Selection.Paste
oDoc.SaveAs FileName:="U:/Text.docx", FileFormat:=wdFormatDocument
oDoc.Close
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With