B
Brad
Thanks for reading my question.
I am just learning how to write code for Outlook and am
having problems with a For Each... Nex loop.
I can't seem to assign my variable the right value, see
comments in code.
Thanks again,
Brad
Public Sub Test2()
Dim i As Variant, MyCollection As Variant
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set MyNewFolder = myFolder.Folders
("EarlyShippingReportsNew")
'myFolder.Display
'I Get Stuck Here
'I can't seem to assign i and MyCollection the correct
values.
'I know the code inside the loop works as I had it all
running before I added the loop
'I want the code to execute on each e-mail in myNewFolder
Set i = MailItem
Set MyCollection = MyNewFolder
For Each i In MyCollection
Set myItem = MyNewFolder.Items(1)
myItem.Display
MsgBox myItem.Subject
MsgBox myItem.Body
MsgBox myItem.Text
'myItem.Close
Set myDestFolder = myFolder.Folders
("EarlyShippingReportsSent")
myItem.Move myDestFolder
Next
End Sub
I am just learning how to write code for Outlook and am
having problems with a For Each... Nex loop.
I can't seem to assign my variable the right value, see
comments in code.
Thanks again,
Brad
Public Sub Test2()
Dim i As Variant, MyCollection As Variant
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set MyNewFolder = myFolder.Folders
("EarlyShippingReportsNew")
'myFolder.Display
'I Get Stuck Here
'I can't seem to assign i and MyCollection the correct
values.
'I know the code inside the loop works as I had it all
running before I added the loop
'I want the code to execute on each e-mail in myNewFolder
Set i = MailItem
Set MyCollection = MyNewFolder
For Each i In MyCollection
Set myItem = MyNewFolder.Items(1)
myItem.Display
MsgBox myItem.Subject
MsgBox myItem.Body
MsgBox myItem.Text
'myItem.Close
Set myDestFolder = myFolder.Folders
("EarlyShippingReportsSent")
myItem.Move myDestFolder
Next
End Sub