Ive seen a couple of macro's for Loading up Lotus Notes and putting an attachment in and sending it off.
Its almost finished it sends the email, but dont know how to send a folder, it works with a PDF file, but I have a bunch of PDF files in a folder which i want to send.
How do i format the email to read:
"
Hello
Please Find Attachment
(Attachment)
Signature
"
Any Help is appreciated, Thanks
Sub SendEmail()
Dim WatchRange As Range
Dim IntersectRange As Range
Dim x As Integer
Dim UserName As String
Dim MailDbName As String
Dim Recipient As Variant
Dim Maildb As Object
Dim MailDoc As Object
Dim Attachment As String
Dim Session As Object
Dim stSignature As String
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' Open and locate current LOTUS NOTES User
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If
' Create New Mail and Address Title Handlers
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
Maildb.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0)
' Select range of e-mail addresses
MailDoc.SendTo = "joe bloggs"
MailDoc.subject = "Work"
MailDoc.Body = "Hello" & " " & " Please find attachment."
MailDoc.SAVEMESSAGEONSEND = True
Attachment = "c:\03-11\4267.pdf"
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "")
On Error Resume Next
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
MailDoc.PostedDate = Now()
On Error GoTo errorhandler1
MailDoc.SEND 0, Recipient
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
.ScreenUpdating = True
.DisplayAlerts = True
On Error GoTo errorhandler1
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
End With
End Sub
I have altered my macro, It nows add the signature but the format is wrong and it doesn't attach the file.
Sub SendEmail()
Dim WatchRange As Range
Dim IntersectRange As Range
Dim x As Integer
Dim UserName As String
Dim MailDbName As String
Dim Recipient As Variant
Dim Maildb As Object
Dim MailDoc As Object
Dim Attachment As String
Dim Session As Object
Dim stSignature As String
Dim ws As Object 'Lotus Workspace
Dim objProfile As Object
Dim rtiSig As Object, rtitem As Object, rtiNew As Object
Dim uiMemo As Object
Dim strToArray() As String, strCCArray() As String, strBccArray() As String
Dim strTo As String, strCC As String, strBcc As String, _
strObject As String, strBody As String, strAttachment As String, blnSaveit As Boolean
Dim strSignText As String, strMemoUNID As String
Dim intSignOption As Integer
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' Open and locate current LOTUS NOTES User
Set Session = CreateObject("Notes.NotesSession")
Set ws = CreateObject("Notes.NotesUIWorkspace")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If
' Create New Mail and Address Title Handlers
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
stSignature = Maildb.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0)
' Select range of e-mail addresses
MailDoc.SendTo = "JJunoir"
MailDoc.subject = ""
MailDoc.Body = "Hello" & " " & " Please find attachment,"
MailDoc.SAVEMESSAGEONSEND = True
Set objProfile = Maildb.GETPROFILEDOCUMENT("CalendarProfile")
intSignOption = objProfile.GETITEMVALUE("SignatureOption")(0)
strSignText = objProfile.GETITEMVALUE("Signature")(0)
Attachment = "c:\Debit Notes 03-11\"
If strAttachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", strAttachment, "Attachment")
On Error Resume Next
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Open memo in ui
Set uiMemo = ws.EDITDOCUMENT(True, MailDoc)
Call uiMemo.GotoField("Body")
'Check if the signature is automatically inserted
If objProfile.GETITEMVALUE("EnableSignature")(0) <> 1 Then
If intSignOption = 2 Then
Call uiMemo.ImportItem(objProfile, "Signature_Rich")
End If
End If
Call uiMemo.GotoField("Body")
'Save the mail doc
strMemoUNID = uiMemo.DOCUMENT.UNIVERSALID
uiMemo.DOCUMENT.MailOptions = "0"
Call uiMemo.Save
uiMemo.DOCUMENT.SaveOptions = "0"
Call uiMemo.Close
Set uiMemo = Nothing
Set MailDoc = Nothing
'Get the text and the signature
Set MailDoc = Maildb.GETDOCUMENTBYUNID(strMemoUNID)
Set rtiSig = MailDoc.GETFIRSTITEM("Body")
Set rtiNew = MailDoc.CREATERICHTEXTITEM("rtiTemp")
Call rtiNew.APPENDTEXT(strBody)
Call rtiNew.APPENDTEXT(Chr(10)): Call rtiNew.APPENDTEXT(Chr(10))
Call rtiNew.APPENDRTITEM(rtiSig)
'Remove actual body to replace it with the new one
Call MailDoc.RemoveItem("Body")
Set rtitem = MailDoc.CREATERICHTEXTITEM("Body")
Call rtitem.APPENDRTITEM(rtiNew)
MailDoc.Save False, False
Set uiMemo = ws.EDITDOCUMENT(True, MailDoc)
MailDoc.PostedDate = Now()
On Error GoTo errorhandler1
MailDoc.SEND 0, Recipient
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
.ScreenUpdating = True
.DisplayAlerts = True
errorhandler1:
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
End With
End Sub
This is what it produces with no attachment
Kind Regards
J JuniorHello Please find attachment,
If your goal is to manipulate the Lotus Notes client user interface, then you started half correctly by using "Notes.NotesSession" instead of "Lotus.NotesSession". The "Notes." prefix gets you the OLE classes instead of the COM classes that you would have gotten with the "Lotus" prefix, and you definitely need to be using the OLE classes - but you still chose the wrong root object.
The NotesSession class and all the classes that descend from it, which are available in both the OLE and COM classes, are referred to as "back-end classes", which means they do not manipulate the user interface at all.
You need to use the "front-end classes" if you want to manipulate the UI, and the root object for that is "Notes.NotesUIWorkspace". In many cases, you may find that you want a combination of the back-end and front-end classes. For example, the NotesUIWorkspace.EditDocument (front-end) takes a NotesDocument (back-end) argument, allowing you to open the UI for a document that you located by going behind the scenes to find it.
Related
I have tried everything to read a mail from office 365 outlook but I am not able to read it. Every time Sender address is coming empty.
Error That I am getting is :
Run-time error: ‘287’
Application-defined or object-defined error.
Please find the code that I am using.
Option Explicit
Sub Mail()
Dim xNameSpace As Outlook.Namespace
Dim xFolder As Outlook.Folder
Dim xOutlookApp As Outlook.Application
Set xOutlookApp = New Outlook.Application
Set xNameSpace = xOutlookApp.Session
Set xFolder = xNameSpace.GetDefaultFolder(olFolderInbox)
Set xFolder = xFolder.Folders("Retail")
' Set Outlook application object.
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
Dim objNSpace As Object ' Create and Set a NameSpace OBJECT.
' The GetNameSpace() method will represent a specified Namespace.
Set objNSpace = objOutlook.GetNamespace("MAPI")
Dim myFolder As Object ' Create a folder object.
Set myFolder = objNSpace.GetDefaultFolder(olFolderInbox)
Dim objItem As Object
Dim iRows, iCols As Integer
iRows = 2
' Loop through each item in the folder.
For Each objItem In xFolder.Items
If objItem.Class = olMail Then
Dim GetSenderAddress As String
Dim objMail As Outlook.MailItem
Set objMail = objItem
Dim mailType As String
mailType = objMail.SenderEmailType
If mailType = "EX" Then
' GetSenderAddress = GetExchangeSenderAddressNew(objMail)
FindAddress (objMail.SenderEmailAddress)
Else
GetSenderAddress = objMail.SenderEmailAddress
End If
Cells(iRows, 1) = objMail.SenderEmailAddress
Cells(iRows, 2) = objMail.To
Cells(iRows, 3) = objMail.Subject
Cells(iRows, 4) = objMail.ReceivedTime
End If
iRows = iRows + 1
Next
Set objMail = Nothing
' Release.
Set objOutlook = Nothing
Set objNSpace = Nothing
Set myFolder = Nothing
End Sub
Private Function GetExchangeSenderAddress(objMsg As MailItem) As String
Dim oSession As Object
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False
Dim sEntryID As String
Dim sStoreID As String
Dim oCdoMsg As Object
Dim sAddress As String
Const g_PR_SMTP_ADDRESS_W = &H39FE001F
sEntryID = objMsg.EntryID
sStoreID = objMsg.Parent.StoreID
Set oCdoMsg = oSession.GetMessage(sEntryID, sStoreID)
sAddress = oCdoMsg.Sender.Fields(g_PR_SMTP_ADDRESS_W).Value
Set oCdoMsg = Nothing
oSession.Logoff
Set oSession = Nothing
GetExchangeSenderAddress = sAddress
End Function
Another Code is:
Sub Mail()
Dim jsObj As New ScriptControl
jsObj.Language = "JScript"
With jsObj
.AddCode "outlookApp = new ActiveXObject('Outlook.Application'); nameSpace = outlookApp.getNameSpace('MAPI'); nameSpace.logon('','',false,false); mailFolder = nameSpace.getDefaultFolder(6); var Inbox = mailFolder.Folders; var box = Inbox.Item('Retail').Items; "
End With
End Sub
Please let me know if i can read sender address of a mail in office 365 outlook.
First of all, the following lines of code iterates over all items in the folder:
' Loop through each item in the folder.
For Each objItem In xFolder.Items
If objItem.Class = olMail Then
Where you don't check whether it is received or composed item. Composed emails may not have the Sender-related properties set yet, so you can use the CurrentUser property which returns the display name of the currently logged-on user as a Recipient object.
Note, in case of Exchange accounts configured you may use the AddressEntry.GetExchangeUser property which returns an ExchangeUser object that represents the AddressEntry if the AddressEntry belongs to an Exchange AddressList object such as the Global Address List (GAL) and corresponds to an Exchange user.
The ExchangeUser.PrimarySmtpAddress property returns a string representing the primary Simple Mail Transfer Protocol (SMTP) address for the ExchangeUser.
I am writing code in VBA (in Excel) that puts Outlook contacts into a distribution list.
It works so far, but error handling in case the contact does not exist is not working. MS says
If the specified recipient is not valid, the AddMember method will
fail.
So how do you notice if the method fails?
Public Function olAddContactToList(ByVal sLastName As String, _
Optional ByVal sFirstName As String, _
Optional ByVal sGroup As String) As Boolean
Dim oOutlook As Object ' Outlook.Application
Dim oNameSpace As Object ' Outlook.NameSpace
Dim oMAPIFolder As Object ' Outlook.MAPIFolder
Dim oContact As Object ' Outlook.ContactItem
Dim oList As Object ' Outlook.DistListItem
Dim oMail As Object ' Outlook.MailItem
Dim oRecip As Object ' Outlook.Recipient
Const olFolderContacts = 10
On Error GoTo ErrHandler
Set oOutlook = CreateObject("Outlook.Application")
Set oNameSpace = oOutlook.GetNamespace("MAPI")
Set oMAPIFolder = oNameSpace.GetDefaultFolder(olFolderContacts)
Set oList = oNameSpace.GetDefaultFolder(olFolderContacts).Items(sGroup)
'Adds a member to a new distribution list
Set oMail = oOutlook.CreateItem(olMailItem)
'Create recipient for distlist
Set oRecip = oOutlook.Session.CreateRecipient(sFirstName & " " & sLastName)
oRecip.Resolve
oList.AddMember oRecip
oList.Save
olAddContactToList = True
ErrHandler:
If Err.Number <> 0 Then
MsgBox "Fehler beim Hinzufügen des Outlook-Kontakts zu einer Liste." & vbCrLf & _
CStr(Err.Number) & " " & Err.Description, vbExclamation + vbOKOnly
olAddContactToList = False
End If
Set oContact = Nothing
Set oMAPIFolder = Nothing
Set oNameSpace = Nothing
Set oOutlook = Nothing
Set oList = Nothing
Set oMail = Nothing
Set oRecip = Nothing
End Function
I have tried
Dim AddCheck As Long
AddCheck = oList.AddMember(oRecip)
but AddCheck stays 0 irrespective of the contact existing and being successfully added to the list or not existing and failing to be added.
As the result of Recipient.Resolve is either True or False (says Microsoft), you should check that.
Otherwise you only have a firstname and lastname, but not a full email address:
If Not oRecip.Resolve Then
' no resulting email address
Else
' email address found, go further
End If
As DistListItem.AddMember even raises no error, if you try to add a simple phone number string (just doesn't add it), I suggest to compare DistListItem.MemberCount (oList.MemberCount in your code) additionally before and after trying to add a new member.
By that you`ll either get an error or an unchanged member count, if something went wrong, and can do further checks.
I am trying to get the string after a word that gives me the needed data and all the phrase after every "-" into a new cell in excel except in RE: , where I omit "RE:" and only leave the TS... ticket ID.
This code works by selecting the emails in outlook and then running the macro for only that selected emails.
This is an example of a subject that has the
Example Subject
RE: TS001889493 - Translation failure - Inbound - ( VEXP/ HONCE/ Document Type 214 - Map AVE_NMHG_I_214_4010_XML_SAT - Error Conditional Relationship Error in N103 (0066) [ ref:_00D50c9MW._5000z1J3cG8:ref ]
Example of body
Dear Valued Trading Partner,
We received the attached 214 transactions from Sender ID: VEXP/ Receiver ID: HONCE that failed due to Conditional Relationship Error in the N1_03 (0066).
As per the map logic, If either N103 or N104 is present, then the other is required as they are in conditional relationship with each other.
But in the input file received, N104 value is missing hence the error.
Transaction Details: #4#
Attached
Please correct and resend the data.
Thank you,
Simon Huggs | Sass support - Basic
ref:_00D50c9MW._5000z1J3cG8:ref
What happens in the #num# is that it gets the sum of all these after making a match of the "TS" ticket ID.
This is the code I have up until now
Option Explicit
Sub WritingTicketNumberAndfailuresnew()
Dim xlApp As Object
Dim xlWB As Object
Dim xlSheet As Object
Dim rCount, STicket, SticketNumber As Long
Dim bXStarted As Boolean
Dim enviro As String
Dim strPath, SSubject As String
Dim currentExplorer As Explorer
Dim Selection As Selection
Dim olItem As Outlook.MailItem
Dim obj As Object
Dim strColS, strColB, sassupport, sMailDateReceived, SFrom As String
Dim Actions1, Actions2, Actions3, Actions4 As Boolean
Dim I, cnt, email_needed As Integer
' Get Excel set up
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Application.StatusBar = "Please wait while Excel source is opened ... "
Set xlApp = CreateObject("Excel.Application")
bXStarted = True
End If
On Error GoTo 0
'Open a specific workbook to input the data the path of the workbook under the windows user account
enviro = CStr(Environ("USERPROFILE"))
strPath = enviro & "\Documents\topthreeticket.xlsx"
Set xlWB = xlApp.Workbooks.Open(strPath)
Set xlSheet = xlWB.Sheets("Sheet1")
' Add column names
xlSheet.Range("A1") = "Email Subject"
xlSheet.Range("B1") = "Map Name"
xlSheet.Range("C1") = "Case Number"
xlSheet.Range("D1") = "No. Of Failures"
xlSheet.Range("E1") = "Date"
xlSheet.Range("F1") = "Week Number"
sassupport = "sassuport#sass.com"
On Error Resume Next
'Find the next empty line of the worksheet
rCount = xlSheet.Range("A" & xlSheet.Rows.Count).End(-4162).Row
'needed for Exchange 2016. Remove if causing blank lines.
rCount = rCount + 1
' get the values from outlook
Set currentExplorer = Application.ActiveExplorer
Set Selection = currentExplorer.Selection
For Each obj In Selection
Set olItem = obj
'collect the fields for ticket number and failure count
strColS = olItem.Subject
strColB = olItem.Body
SFrom = olItem.SenderEmailAddress
sMailDateReceived = olItem.ReceivedTime
Dim sFailures, stmp1, stmp2, stmp3 As String
Dim RegX As Object, Mats As Object
Dim Found As Boolean
' Check the number of failures from body
sFailures = "0"
stmp1 = strColB
Set RegX = CreateObject("VBScript.RegExp")
With RegX
.Global = True
.Pattern = "#\d+#"
Set Mats = .Execute(stmp1)
End With
If (RegX.Test(stmp1)) Then
stmp2 = Mats(0)
Found = True
stmp3 = Mid(stmp2, 2, Len(stmp2) - 2)
sFailures = stmp3
Else
With RegX
.Pattern = "#d\d+"
Set Mats = .Execute(stmp1)
End With
If (RegX.Test(stmp1)) Then
stmp2 = Mats(0)
Found = True
stmp3 = Mid(stmp2, 2, Len(stmp2) - 1)
sFailures = stmp3
End If
End If
Set Mats = Nothing
Set RegX = Nothing
Dim tmp As String
Dim RegX2 As Object, Mats1 As Object
tmp = strColS
Set RegX2 = CreateObject("VBScript.RegExp")
With RegX2
.Global = True
.Pattern = "TS00\d{7}"
Set Mats1 = .Execute(tmp)
End With
If (RegX2.Test(tmp)) Then
Set Mats1 = RegX2.Execute(tmp)
tmp = Mats1(0)
Else
With RegX2
.Pattern = "T.S\d{9}"
Set Mats1 = .Execute(tmp)
End With
If (RegX.Test(tmp)) Then
tmp = Mats1(0)
End If
End If
Set Mats1 = Nothing
Set RegX2 = Nothing
Dim tempticketnum, tmpdate As String
Dim ticketnumposition As Integer
'write them in the excel sheet
If SFrom = sassupport Then
xlSheet.Range("A" & rCount) = strColS
xlSheet.Range("B" & rCount) = tmp2
xlSheet.Range("C" & rCount) = tmp
xlSheet.Range("D" & rCount) = sFailures ' number of failures
xlSheet.Range("E" & rCount) = sMailDateReceived
rCount = rCount + 1
End If
Next
Set olItem = Nothing
Set obj = Nothing
Set currentExplorer = Nothing
Set xlSheet = Nothing
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
You can use the SPLIT function in VBA, something like so
Sub x()
Dim s As String
Dim a() As String
s = "this-will-test-this-out"
a = Split(s, "-")
Range("a1").Resize(UBound(a) + 1, 1).Value = Application.Transpose(a)
End Sub
I'm using VBA in Excel 2010, with Outlook 2010 (already open).
How could I write a sub such that:
1 Outlook address book opens;
2 The user selects a contact and clicks ok;
3 The contact's first name, last name and email address are stored in cells of the active worksheet?
I tried with this method without success: SelectNamesDialog Object
Also I'm not sure if I need to use: Application.GetNamespace("MAPI")
You are on the right avenue, the SelectNamesDialog is exactly what you are looking for. The GetNamepsace method equals to the Session property used in the sample code:
Sub ShowContactsInDialog()
Dim oDialog As SelectNamesDialog
Dim oAL As AddressList
Dim oContacts As Folder
Set oDialog = Application.Session.GetSelectNamesDialog
Set oContacts = _
Application.Session.GetDefaultFolder(olFolderContacts)
'Look for the address list that corresponds with the Contacts folder
For Each oAL In Application.Session.AddressLists
If oAL.GetContactsFolder = oContacts Then
Exit For
End If
Next
With oDialog
'Initialize the dialog box with the address list representing the Contacts folder
.InitialAddressList = oAL
.ShowOnlyInitialAddressList = True
If .Display Then
'Recipients Resolved
'Access Recipients using oDialog.Recipients
End If
End With
End Sub
You may find the following articles helpful:
How to automate Outlook from another program
Automating Outlook from a Visual Basic Application
Here is how to get all the details from a selected contact in the GAL:
You need to open the Global Address List and not the contacts from the contact folder, and use an Outlook.ExchangeUser object as explained on this page: see last answer from David Zemens.
Private Sub cmdSetProjectMember1_Click()
Dim olApp As Outlook.Application
Dim oDialog As SelectNamesDialog
Dim oGAL As AddressList
Dim myAddrEntry As AddressEntry
Dim exchUser As Outlook.ExchangeUser
Dim AliasName As String
Dim FirstName As String
Dim LastName As String
Dim EmailAddress As String
Set olApp = GetObject(, "Outlook.Application")
Set oDialog = olApp.Session.GetSelectNamesDialog
Set oGAL = olApp.GetNamespace("MAPI").AddressLists("Global Address List")
With oDialog
.AllowMultipleSelection = False
.InitialAddressList = oGAL
.ShowOnlyInitialAddressList = True
If .Display Then
AliasName = oDialog.Recipients.Item(1).Name
Set myAddrEntry = oGAL.AddressEntries(AliasName)
Set exchUser = myAddrEntry.GetExchangeUser
If Not exchUser Is Nothing Then
FirstName = exchUser.FirstName
LastName = exchUser.LastName
EmailAddress = exchUser.PrimarySmtpAddress
'...
MsgBox "You selected contact: " & vbNewLine & _
"FirstName: " & FirstName & vbNewLine & _
"LastName:" & LastName & vbNewLine & _
"EmailAddress: " & EmailAddress
End If
End If
End With
Set olApp = Nothing
Set oDialog = Nothing
Set oGAL = Nothing
Set myAddrEntry = Nothing
Set exchUser = Nothing
End Sub
I have a workbook from which I create a PDF based on a range of cells. This all works fine. I do this separately from producing the Email so it can be checked before its Emailed.
I then create an Email from the same workbook to send with the PDF attached. The body of the Email is created from a another range of cells from the workbook. Again, no problems with doing that.
The problems came when I send it. The Email sends fine and the body of the Email is fine but just without the attachment.
I have triple checked the file path of the attachment (even moving it to a simpler path to test) and change it to attach a simple word document. I have also used two different Email providers 1&1 and GMail but with the same problem. That attachment just does not want to leave me.
I have also noticed that I now have a message appear by the mouse pointer whenever I hover over a link of any kind. The message is : error while processing request - wrong response. I can only guess it has something to do with all the test Emails I have been firing off but no idea what it means or how to get rid of it. Have I something still running?
Sub CDO_Send_Email_Angebot()
Dim Rng As Range
Dim iMsg As Object
Dim ws As Worksheet
Dim Flds As Variant
Dim iConf As Object
Dim PdfFile As String
PdfFile = Sheets("5_Angebot").Range("E97").Value & "." & Sheets("5_Angebot").Range("E98").Value
'MsgBox rngAttachment
'---------- Get the Emails from a cells on the sheet
Dim SendItTo As String
Dim SenderEmail As String
Dim Subjectext As String
SendItTo = Sheets("5_Angebot").Range("E94").Value
SenderEmail = Sheets("5_Angebot").Range("E95").Value
SubjectText = Sheets("5_Angebot").Range("E96").Value
'---------
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = SenderEmail
'.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "**********"
'.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.1and1.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "***********"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
' ------
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Rng = Nothing
On Error Resume Next
Set Rng = Selection.SpecialCells(xlCellTypeVisible)
Set Rng = Sheets("5_Angebot").Range("C101:J121")
Set iMsg = CreateObject("CDO.Message")
With iMsg
Set .Configuration = iConf
.To = SendItTo
.From = SenderEmail
.Subject = SubjectText
.HTMLBody = RangetoHTML(Rng)
'.Attachments.Add PdfFile
.Attachments.Add ("D:\Corinne\test.docx")
.Send
End With
Set iMsg = Nothing
' --------
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
A quick google search suggests the appropriate method is AddAttachment, not Attachments.Add (the latter is for MS Outlook). There may be other errors in your method calls, so my recommendation above still stands: debug without On Error Resume Next