简体   繁体   中英

Is there a way to convert the active document format (docm) to a docx when attaching it to an email in outlook

I've set up a form that fills out the active document. Obviously this document is macro enabled because i'm using VBA. Once form is completed and submitted it will attach the active document to an outlook email. My IT team doesn't allow macro enabled documents to be sent over our systems so the email wont be allowed to send with a .docm attachment

I've tried to convert the document myself, but i'm not very savvy with VBA in this regard.

This is the code I have so far.

Private Sub OpenEmailAndAttach()
    Dim olkApp As Object
    Dim strSubject As String
    Dim strTo As String
    Dim strBody As String
    Dim strAtt As String

    strSubject = "Expenditure Approval Request"
    strBody = "Hi, " & Chr(10) & Chr(10) & "Please could I request approval RE: works" & Chr(10) & Chr(10) & "EAF is attached" & Chr(10) & Chr(10) & "Regards, " & Chr(10) & "Name"
    strTo = "email@email.com"

    strAtt = ActiveDocument.FullName

    Set olkApp = CreateObject("outlook.application")
    With olkApp.createitem(0)
        .to = strTo
        .Subject = strSubject
        .body = strBody
        .attachments.Add strAtt
        '.send
        .Display
    End With
    Set olkApp = Nothing
End Sub

It works, but I need it to be attached as a .docx (non macro enabled) not a .docm file. Is it possible to do this type of conversion while attaching a document?

如果将代码添加到文档模板而不是文档本身,则文档可以始终以docx格式保存。

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