Skip
OK, I've never heard of CDOs, but a quick search of the web tells me that it is a way of accessing Outlook data without triggering alerts. All sounds like what I need, so thank you for that pointer.
I think I understand that code. Am I right in thinking that your code sends emails from Excel, based on the string parameters in CDO_Mail?
If so, I don't see how it helps - which is likely my fault for not being clear. Or perhaps it does help, but I am being clueless.
Situation - I am using VBA in excel, to review emails held within a given folder in outlook, to record information about each email in the active excel worksheet.
Every time the code attempts to work with each email I get the above alert msg, which is my only (current) problem.
My current code follows (heavily cribbed from the quoted thread - so many thanks to CMP!):
Code:
Sub GetOutlookItems()
On Error GoTo GetOutlookItems_Error
Dim objOutlook As Object
Dim objFolder As Object
Dim objTarget As Object
Dim objItem As Object
Dim wksOutput As Worksheet
Dim rngToSort As Range
Dim lngRow As Long
Set wksOutput = ActiveSheet
lngRow = 1
wksOutput.Cells(lngRow, 1) = "SenderName"
wksOutput.Cells(lngRow, 2) = "Subject"
wksOutput.Cells(lngRow, 3) = "ConversationTopic"
wksOutput.Cells(lngRow, 4) = "ConversationIndex"
wksOutput.Cells(lngRow, 5) = "To"
wksOutput.Cells(lngRow, 6) = "SentOn"
lngRow = 2
Set objOutlook = GetObject(, "Outlook.Application")
Set objFolder = objOutlook.session.Folders([b][i]ParentFolder[/i][/b])
Set objTarget = objFolder.Folders([b][i]Subfolder[/i][/b]).Folders([b][i]Subfolder[/i][/b]).Folders([b][i]Subfolder[/i][/b])
For Each objItem In objTarget.Items
If objItem.Class = 43 Then
With objItem
wksOutput.Cells(lngRow, 1) = .SenderName
wksOutput.Cells(lngRow, 2) = .Subject
wksOutput.Cells(lngRow, 3) = .ConversationTopic
wksOutput.Cells(lngRow, 4) = GUIDToString(.ConversationIndex)
wksOutput.Cells(lngRow, 5) = .To
wksOutput.Cells(lngRow, 6) = .SentOn
End With
lngRow = lngRow + 1
End If
Next objItem
wksOutput.Range("A1:F" & lngRow).Sort Range("B2"), xlAscending, Range("C2"), , xlAscending, , , xlYes
Clean_Up:
Set wksOutput = Nothing
Set objItem = Nothing
Set objTarget = Nothing
Set objFolder = Nothing
Set objOutlook = Nothing
Exit Sub
GetOutlookItems_Error:
Debug.Print Err.Number, Err.Description
Resume Clean_Up
End Sub
Function GUIDToString(GUID As Variant) As String
Dim arrByte() As Byte
Dim intOrdinal As Integer
arrByte = GUID
For intOrdinal = 0 To UBound(arrByte)
GUIDToString = GUIDToString & Hex$(arrByte(intOrdinal))
Next intOrdinal
End Function
The subfolder I chose within Outlook has 63 msgs in it, so I had to click "Yes" to the alert 63 times.
As mentioned, your point about CDOs would appear to be aiming me in the right direction, though I am concerned that it appears (from the web search) to not be part of the standard build of Outlook (so I may have trouble using it at work). However, those problems aside...
In order to use CDOs, I presume my current code is worthless?
Or can it be easily adapted to work with CDO objects?
If so, would it simply be the inclusion of a line after
Set objOutlook= GetObject(, "Outlook.Application")
as some sort of
Set objCDO= objOutlook.CDO 'A wild stab in the dark!!
Set objFolder = objCDO.session.Folders(parentfolder)
......
or am I way off base? (Apologies for my lack of knowledge on this subject!)
Many thanks in advance
Fen