vbaoutlookpowerpointpowerpoint-2010

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

Solution

  • 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