WORD PDF EMAIL VBA

jakub1241996

New Member
Joined
Jan 21, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello please help not working PDF

Sub PDF_SAVE()
Application.ScreenUpdating = False
Dim PatientName As String, Dt As String

myFolderName = Environ("userprofile") & "\SPMO\Reklamace - Reklamace\"
Dim strFileName As String
Dim objOutlook As Object
Dim objMailItem As Object


With ActiveDocument
strFileName = Replace(ActiveDocument.FullName, ".docm", ".pdf")
Dl = " " & Trim(Split(Split(.Range.Text, "Dodací list:")(1), vbCr)(0))
Shipment = " " & Trim(Split(Split(.Range.Text, "Shipment (ASTRO WMS):")(1), vbCr)(0))
RP = "__RP"
ActiveDocument.SaveAs2 myFolderName & RP & Dl & Shipment & ".pdf", FileFormat:=wdFormatText, AddToRecentFiles:=False
ActiveDocument.ExportAsFixedFormat OutputFileName:=strFileName, _
ExportFormat:=wdExportFormatPDF

Set objOutlook = CreateObject("Outlook.Application")
Set objMailItem = objOutlook.CreateItem(0) ' 0 = olMailItem
With objMailItem
.Subject = "& RP & Dl &"
.Body = "My Message"
.To = "jakub@sp.cz"
.Attachments.Add strFileName
.Display
End With

Kill strFileName

Set objMailItem = Nothing
Set objOutlook = Nothing
End With
Dim bExists As Boolean
Dim MyPrint As Dialog

' ensure our doc variable exists
bExists = False
For Each varItem In ActiveDocument.CustomDocumentProperties
If varItem.Name = "Copies" Then
bExists = True
Exit For
End If
Next varItem

' initialize document variable if doesn't exist
If Not bExists Then
ActiveDocument.CustomDocumentProperties.Add _
Name:="Copies", LinkToContent:=False, _
Type:=msoPropertyTypeNumber, Value:=1
End If

Set MyPrint = Dialogs(wdDialogFilePrint)
With MyPrint
.NumCopies = ActiveDocument.CustomDocumentProperties("Copies")
.Show
End With

ActiveDocument.CustomDocumentProperties("Copies") = _
MyPrint.NumCopies


Dim windowsObject As Object


Application.ScreenUpdating = False

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Evening all,

i've nearly cracked this but i'm stuck on the last bit. I need it to send the saved pdf, not the open word doc, any ideas?
VBA Code:
Sub PDF_SAVE()
Application.ScreenUpdating = False
Dim PatientName As String, Dt As String

myFolderName = Environ("userprofile") & "\SPMO\Reklamace - Reklamace\"
Dim strFileName As String
Dim objOutlook As Object
Dim objMailItem As Object


With ActiveDocument
strFileName = Replace(ActiveDocument.FullName, ".docm", ".pdf")
Dl = " " & Trim(Split(Split(.Range.Text, "Dodací list:")(1), vbCr)(0))
Shipment = " " & Trim(Split(Split(.Range.Text, "Shipment (ASTRO WMS):")(1), vbCr)(0))
RP = "__RP"
ActiveDocument.SaveAs2 myFolderName & RP & Dl & Shipment & ".pdf", FileFormat:=wdFormatText, AddToRecentFiles:=False
ActiveDocument.ExportAsFixedFormat OutputFileName:=strFileName, _
ExportFormat:=wdExportFormatPDF

Set objOutlook = CreateObject("Outlook.Application")
Set objMailItem = objOutlook.CreateItem(0) ' 0 = olMailItem
With objMailItem
.Subject = "& RP & Dl &"
.Body = "My Message"
.To = "[EMAIL]jakub@sp.cz[/EMAIL]"
.Attachments.Add strFileName
.Display
End With

Kill strFileName

Set objMailItem = Nothing
Set objOutlook = Nothing
End With
Dim bExists As Boolean
Dim MyPrint As Dialog

' ensure our doc variable exists
bExists = False
For Each varItem In ActiveDocument.CustomDocumentProperties
If varItem.Name = "Copies" Then
bExists = True
Exit For
End If
Next varItem

' initialize document variable if doesn't exist
If Not bExists Then
ActiveDocument.CustomDocumentProperties.Add _
Name:="Copies", LinkToContent:=False, _
Type:=msoPropertyTypeNumber, Value:=1
End If

Set MyPrint = Dialogs(wdDialogFilePrint)
With MyPrint
.NumCopies = ActiveDocument.CustomDocumentProperties("Copies")
.Show
End With

ActiveDocument.CustomDocumentProperties("Copies") = _
MyPrint.NumCopies


Dim windowsObject As Object


Application.ScreenUpdating = False

End Sub

[URL='https://www.mrexcel.com/board/threads/word-pdf-email-vba.1227675/reply?quote=6006669']Quote[/URL] [URL='https://www.mrexcel.com/board/threads/word-pdf-email-vba.1227675/reply?quote=6006669']Reply[/URL]
[URL='https://www.mrexcel.com/board/posts/6006669/report']Report[/URL]
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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