thanks for the pointers Michael.
i'm now on a machine without outlook. Do you think the following will
work:
option base 1
Dim objOutlook As Object
Dim objMailItem As Object
Dim myCreatedEmails() As Outlook.MailItem'Object
Sub CreateAndDisplayEmails()
Set objOutlook = CreateObject("Outlook.Application")
Erase myCreatedEmails
For i = 1 To 3
Set objMailItem = objOutlook.CreateItem(0)
With objMailItem
.To = "Tester" & i
.Subject = "Tester" & i
End With
ReDim preserve myCreatedEmails(i)
myCreatedEmails(i) = objMailItem
Next i
For k = 1 To UBound(myCreatedEmails)
myCreatedEmails(k).Display
Next k
End Sub
I've changed the type from object to outlook.mailitem(not too sure if
this will work from Excel without a reference to Outllook model?)
I've added the Preserve word to stop the array being overwritten.
Also added option base 1 as I like to start at 1.
will this work now?
help appreciated.
Jason.
Michael Bauer wrote:
Am 23 Jun 2006 09:26:43 -0700 schrieb WhytheQ:
What value is k the first time? And what type is myCreatedEmails?
k must be 0 the first time. If myCreatedEmails is an object type then you
must use the Set statement.
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --
I'm using the following code, from Excel, with no reference to Outlook:
Dim objOutlook As Object
Dim objMailItem As Object
Dim myCreatedEmails() As Object
Sub CreateAndDisplayEmails()
Set objOutlook = CreateObject("Outlook.Application")
Erase myCreatedEmails
For i = 1 To 3
Set objMailItem = objOutlook.CreateItem(0)
With objMailItem
.To = "Tester" & i
.Subject = "Tester" & i
End With
ReDim myCreatedEmails(k)
'##### falls down on next line #####
myCreatedEmails(k) = objMailItem
k = k + 1
Next i
For k = 1 To UBound(myCreatedEmails)
myCreatedEmails(k).Display
Next k
End Sub
...I've marked where it already falls down and I assume even if this
line is fixed then it'll fall down later on on the line
"myCreatedEmails(k).Display"
The above must be pretty bl##dy close!...can anyone help?
Help appreciated
Jason