VBA export PDF, attach to email and send email

Sweedler

Board Regular
Joined
Nov 13, 2020
Messages
132
Office Version
  1. 365
Platform
  1. Windows
Hello

I am using the following code to try to achieve this, but I am running into error issues. I have made the error area in bold text. I am hoping that someone can help me.

Rich (BB code):
Sub Indi_SV_generator()

Dim OutApp As Object
Dim Outmail As Object

Set OutApp = CreateObject("outlook.application")
Set Outmail = OutApp.CreateItem(0)

Dim bolaget As String
Dim plats As String
Dim namn As String
Dim year As Integer
Dim month As Integer
Dim day As Integer
Dim i As Integer
Dim a As Integer


Dim filename As Range
Dim savelocation As String


bolaget = Sheet6.Range("K1")
plats = Sheet6.Range("K2")
year = Sheet6.Range("K4")
month = Sheet6.Range("K5")
day = Sheet6.Range("K6")
a = Sheet6.Range("K7")

For i = a To 2 Step -1

namn = Sheet6.Cells(i, 1)
Sheet6.Range("K8") = Sheet6.Cells(i, 1)

    Set filename = Sheet4.Range("A1")
    savelocation = "C:\Users\marcu\Desktop\EXCELLENT HELP - PC\Customers\Moll Wenden\Test folder\ " & "Individuellt - " & namn & " - " & year & "-" & month & "-" & day
   
Sheets("INDI SV").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    filename:=savelocation

With Outmail

    .to = Sheet6.Cells(i, 2)
    .Subject = "RÄTTNING"
    .Body = "vänligen se bifogad fil"
    .attachments.Add (savelocation & ".pdf")

    .display
   
End With

   
Next i

End Sub


The PDF export works flawlessly, but I the export to email is not working.

Hoping that you can help me,
Cheers
 
Last edited by a moderator:
This is mine. Which is a newer form of Outlook. Not sure if that plays into this. But for whatever reason I am still getting error messages.

activex component can't create object 429
 

Attachments

  • Skärmbild 2024-11-18 175835.png
    Skärmbild 2024-11-18 175835.png
    68.8 KB · Views: 3
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Find and select version 12 or higher.
 
Upvote 0
Is this correct now?
Yes, thanks. :)
However, if you want to apply your own formatting to any of the code (like bold &/or red) then you need to use the 'RICH' tags instead of the 'VBA' tags, as I did with your first post.

1731967167705.png


It is also a good idea to indent your code and the tags will preserve that too.
 
Upvote 0

Forum statistics

Threads
1,224,809
Messages
6,181,076
Members
453,020
Latest member
mattg2448

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top