Bonjour
Je reçois un message d'erreur (" bad file name or number ") sur la ligne "Kill PdfFile", censée effacer du Bureau le fichier PDF qui y a été sauvegardé pendant la macro.
Au début tout marchait sur un autre ordinateur. Est-ce éventuellement une macro qui ne fonctionne que sur un seul type de Windows?
Comment peut-on arranger ce problème (je travaille maintenant avec Windows 10 Pro en anglais).
Merci d'avance!
Sub sendemail()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object
' title for email subject
Title = Range("C3") & " " & Range("b5") & " " & "-" & " " & Range("F4") & " " & Range("g4")
' Define PDF filename
PdfFile = ActiveWorkbook.FullName & " " & Range("j62")
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & ".pdf"
' Export activesheet as PDF
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
' Use already open Outlook if possible
On Error Resume Next
Set OutlApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlApp = CreateObject("Outlook.Application")
IsCreated = True
End If
OutlApp.Visible = True
On Error GoTo 0
' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)
' Prepare e-mail
.Subject = Title
.To = "my email"
.CC = " "
.Body = " Hey " & vbLf & vbLf _
& " Please find in attachment the details for preparing salary. " & vbLf & vbLf _
& "Best regards" & vbLf _
& Application.UserName & vbLf & vbLf
.Attachments.Add PdfFile
' Try to send
On Error Resume Next
'.send
.display
Application.Visible = True
If Err Then
MsgBox "Some error occurred", vbExclamation
Else
End If
On Error GoTo 0
End With
' Delete PDF file
Kill PdfFile
' Quit Outlook if it was created by this code
If IsCreated Then OutlApp.Quit
' Release the memory of object variable
Set OutlApp = Nothing
End Sub