A family of Microsoft word processing software products for creating web, email, and print documents.
Indeed, changing the filename extension is not enough; you must also choose the correct file format.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
We have a form that users generate from a template (.dotm template). After filling in the form, the user click a submit button on the form self to send it as attachment via email. It works, but it sends the document with the VBA code behind the submit button. When the attachment is opened at the other end, Word warn about security, Read only, etc.
The VBA code behind the submit button:
How can we remove all codes and save it as a valid .docx document using VBA? If we use “document.SaveAs2” method and change the extension to .docx, the code remain behind document.
Is there other solutions?
Thanks
A family of Microsoft word processing software products for creating web, email, and print documents.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
Indeed, changing the filename extension is not enough; you must also choose the correct file format.
SOLVED
It was code error. I changed the following code and it works.
Thanks
The code is not removed by saving it as .docx. My code is:
Public Sub btnSubmit_Click()
Dim OL As Object
Dim EmailItem As Object
Dim dDoc As Document
Dim sPath As String
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Set dDoc = ActiveDocument
sPath = "c:\_dump\TESTsave3.docx"
dDoc.SaveAs2 sPath
With EmailItem
.Subject = "Insert Subject Here"
.Body = "TES TEST"
.To = "******@outlook.com"
.Attachments.Add dDoc.FullName
'.Send
.Display
End With
Application.ScreenUpdating = True
Set dDoc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
Saving the file as a macro-free document (*.docx) will delete any code that is present. However, it is better to keep all the code in the template instead. When the macro-free document is created, it can still access the code in the attached template.
Save the document as a .docx document in your code, or...
Consider, instead of a submit button, either a QAT icon linked to a macro in the template or a MacroButton Field that you can have look like a button.