0

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
Community
  • 1
  • 1
Piskota
  • 7
  • 2
  • On the error message dialog, there should be a Debug button. What line is highlighted when you click on that? That's usually the line where the error is. – John Korchok Jul 05 '20 at 18:00
  • Private Sub CommandButton1_Click() ---this one was yellow but i don´t know what is wrong with it – Piskota Jul 05 '20 at 19:20

1 Answers1

0
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
John Korchok
  • 4,723
  • 2
  • 11
  • 20