简体   繁体   中英

Reference to xDoc, declared as Document, generates “user defined type not defined” in PowerPoint VBA

I want in PowerPoint: after a click on the command button, send e-mail with attachment (that same PowerPoint presentation) to specific e-mail address.

I used this based on internet, but I think that xDoc may be a problem?

When I click on the button it says "user defined type not defined" and Private Sub CommandButton1_Click() is then yellow.

Private Sub CommandButton1_Click()
    Dim xOutlookObj As Object
    Dim xEmail As Object
    Dim xDoc As Document
    Application.ScreenUpdating = False
    Set xOutlookObj = CreateObject("Outlook.Application")
    Set xEmail = xOutlookObj.CreateItem(olMailItem)
    Set xDoc = ActiveDocument
    xDoc.Save
    With xEmail
        .Subject = "Lorem ipsum"
        .Body = "Lorem ipsum"
        .To = "xyz@xyz.xyz"
        .Importance = olImportanceNormal
        .Attachments.Add xDoc.FullName
        .Display
    End With
    Set xDoc = Nothing
    Set xEmail = Nothing
    Set xOutlookObj = Nothing
    Application.ScreenUpdating = True
End Sub
Dim xDoc As Document

That's a Word VBA statement. Try:

Dim xPres As Presentation

then change all the xDoc references in the code. ie:

Set xPres = ActivePresentation

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