Hello,
I have a problem attaching a pdf file from my D drive (with my OneDrive on). The same code works just fine when I move the file to my C drive, but not on D...
What am I doing wrong?
The code is not finished, it will send a specific pdf to a person.
I have a problem attaching a pdf file from my D drive (with my OneDrive on). The same code works just fine when I move the file to my C drive, but not on D...
What am I doing wrong?
The code is not finished, it will send a specific pdf to a person.
VBA Code:
Sub btnMailen()
Dim outlookApp As Outlook.Application
Dim myMail As Outlook.MailItem
Dim source_file, to_emails As String
Dim customer As String
Dim sFolderPathPDF As String
Dim nummer As String
Dim sPath As String
Set outlookApp = New Outlook.Application
Set myMail = outlookApp.CreateItem(olMailItem)
customer = Range("M7").Value
mailRange = Range("Klantenlijst!A4:G500")
to_emails = Application.WorksheetFunction.VLookup(customer, mailRange, 7, False)
nummer = Range("D11").Value & " " & Range("M7").Value
'sPath = "C:\testje.txt" 'file is present, and exists
sPath = "D:\1.txt" 'file is present, does not exist ????
' sPath = "D:\OneDrive\Firma\000. Boekhouding\03. Facturen\1.txt" 'file is present, does not exist ????
' vba problem with D drive? Opening the files the common way with explorer is no problem.
If FileOrDirExists(sPath) Then
MsgBox sPath & " exists!"
Else
MsgBox sPath & " does not exist."
End If
'source_file = "D:\OneDrive\Firma\000. Boekhouding\03. Facturen\001. pdf\2021\" & nummer
'myMail.Attachments.Add source_file
'source_file = ThisWorkbook.FullName
'myMail.Attachments.Add source_file
myMail.To = to_emails
myMail.Subject = "Factuurtest"
myMail.Body = "Hi Everyone," & vbNewLine & "Please read these before the meeting." & vbNewLine & "Thanks"
'myMail.Attachments.Add source_file
'myMail.Attachments.Add ("D:\OneDrive\Firma\000. Boekhouding\03. Facturen\001. pdf\2021\" & nummer & "\")
myMail.Display
End Sub