Dim myOlApp As Outlook.Application
Dim myitem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myitem = myOlApp.CreateItemFromTemplate(Me![file])
myitem.Display
It works in the sense, that I can open the file - but it
opens in a "mode" where I cant reply or forward the
message - it opens as if had just created the mail and can
only send it.
If I double-click the .msg file from Explorer, It opens as
if had received the mail - and I can reply and forward it
as I want to.
How do I make it open like this from VBA?
John
*********************
Ted, I took your advise and got the * following code from the MS kb, added
it in a newly created test app... it seems to work so I may have a reference
in my other app that is stopping it from working properly.
The problems I now have with CreateItemFromTemplete is that it drops the
From: (SenderName) field (expected, but this is important to what I am
trying to do..) and the attachments are not created. (..kinda expected..) I
think I will give it up as I am running short of time, and just query the
staffs *.pst files directly.
Thanks heaps for your help...
Regards,
Truck
PS. I just got this from the MS Outlook newsgroup, but I am not sure how I
would implement it?? Any Ideas... (Yeah I know I said I would give up, but I
hate doing that :-)
> About the best I can think of is to use a shellexecute on the *.msg file
and
> then reiterate the Inspectors collection to get the item. Once you have
the
> item, read the properties and close the inspector and move on to the next.
*** A little bit later....
Well I tried the above, and actually got it to work...kinda...If I have the
*.msg file already open in outlook I can use the Inspectors collection to
find all the details I want... But heres the kicker, If I use ShellExecute
(Which does open the *.msg file!) my app continues executing while Outlook
is loading the file... I tried slowing my app down (there is no _Wait_ with
ShellExecute), but when the *.msg file opens I can't get control back to my
app...aarrrggghhh. I would have posted my test app, but vb crashed and I
lost the lot...Not a happy camper!!!!
I hope all this crap makes some sense....Thnx again....
/*
Function OpenEmail()
Dim ol
Dim olns
Dim MyFolder
Dim MyItem
Dim MyForm
' Automation code example.
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set MyFolder = olns.GetDefaultFolder(olFolderInbox)
Set MyItem = ol.CreateItemFromTemplate("c:\temp\test\drafts\test.msg")
Set MyForm = MyItem.FormDescription
MyItem.Close olDiscard
End Function
*/
"Ted Harper" <tha...@nsw.bigpond.net.au> wrote in message
news:t3r99u4g45omqm1be...@4ax.com...
> "Truck" <tr...@bigpond.net.au> wrote:
>
> Hmmm, it *should* work according to a bunch of stuff I found on the
> net (even if it's not documented as working by Microsoft/MSDN). I've
> got to run off to work now, but you should do a google search (web and
> newsgroups) for "Outlook CreateItemFromTemplate msg".
>
> I just found the MS kb article Q208520
> (http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q208520&)
> which explicitly says that method works with *.MSG files. Have a look
> at the minimal code fragment in the article (substituting a MSG file
> for the OFT in the example) and see if it gets close. Alternatively,
> it might be worth paying the $180 to Microsoft (assuming you don't
> have Premier Support or similar and have to pay per-case) to have them
> tell you why what you're trying doesn't work, in the face of this KB
> article...
>
> ted.h.
>
> ---
> Ted Harper (Sydney, Australia)
> Business: ted.h...@btfinancialgroup.com
> Private: tha...@nsw.bigpond.net.au
> Windows/MSN Messenger: harpe...@hotmail.com
> Voice: +61-418-442-342
*********************
"John" <Jo...@nomail.com> wrote in message
news:47c501c1ce08$4201d0c0$9be62ecf@tkmsftngxa03...
Hi John,
I use the Shell Command (unfortunately the command line differs from OS to
OS, in Win98 you may have to use "start" I think).
The following code is running in Outlook 2000 under WinXP:
x = Shell("cmd /c c:\temp\mail.msg", vbHide)
' Wait until Inspector is open and CurrentItem is properly initialized
Do
DoEvents
Loop Until Not ActiveInspector Is Nothing
Do
DoEvents
Loop Until Not ActiveInspector.CurrentItem Is Nothing
Set myMail = Application.ActiveInspector.CurrentItem
You have to make sure that no inspector window is open, when the code is
executed. It can be done like this:
Max = Application.Inspectors.Count
If Max > 0 Then
While Application.Inspectors.Count > 0
Application.ActiveInspector.Close (olPromptForSave)
Wend
End If
HTH
Bernd
I have tried to solve this some time ago - and failed back
then... so I was just hoping for somebody to shpw up with
the magic trick.
To open a *.msg file from Access2000 I have made a
solution where I have an unbound object frame pointing to
a dummy.msg-file. Then I copy the new *.msg-file to this
dummy, and activate the unbound object frame. Then it
opens correctly - i.e I can reply and forward etc.
Only trouble is - I cant change the path to the dummy.msg
from VBA - like if I want to open the *.msg-file without
first copying it but just assigning the relevant path.
One of my colleagues tried to ask this in the Access
newsgroup a couple of days ago - but with no reply.
John
>> BusineÍ{ wÀ Ï <No $\±=ÌãD
>°ì" ss: ted.h...@btfinancialgroup.com
>> Private: tha...@nsw.bigpond.net.au
>> Windows/MSN Messenger: harpe...@hotmail.com
>> Voice: +61-418-442-342
>
>*********************
>
>"John" <Jo...@nomail.com> wrote in message
>news:47c501c1ce08$4201d0c0$9be62ecf@tkmsftngxa03...
>> From Access I open .msg-files with the following code:
>>
>> Dim myOlApp As Outlook.Application
>> Dim myitem As Object
>>
>> Set myOlApp = CreateObject("Outlook.Application")
>> Set myitem = myOlApp.CreateItemFromTemplate(Me![file])
>> myitem.Display
>>
>> It works in the sense, that I can open the file - but it
>> opens in a "mode" where I cant reply or forward the
>> message - it opens as if had just created the mail and
can
>> only send it.
>>
>> If I double-click the .msg file from Explorer, It opens
as
>> if had received the mail - and I can reply and forward
it
>> as I want to.
>>
>> How do I make it open like this from VBA?
>>
>> John
>
>
>.
>
See the response I left to Truck's thread. I think this is the only route
you guys can go now.
"John" <jo...@nomail.com> wrote in message
news:566101c1ced8$bcd99b40$9ae62ecf@tkmsftngxa02...
>> Busineヘ{掫タ マ <No $\ア=フ絅
>ー�" ss: ted.h...@btfinancialgroup.com
* The only issue I have is the *.msg does not start hidden...I'm on Win2k
with Outlook 2k, but its a minor problem....
"Bernd Otte" <bernd...@gmx.de> wrote in message
news:a75ukp$bdo$05$1...@news.t-online.com...
I get the error "Object doesn't support this property or
method" in the shell-statement - and "ActiveInspector"
needs to be defined...
Am I missing a library reference or what?
John
>.
>
Couple of things to note, On my build machine, Win2k (sp2) with VB 6 (sp5)
the "retVal = Shell(..." would work. When I transferred it to my work
machine, Win2k (No service packs) and VB 6 (No service packs), Shell doesn't
work, and I needed to put in the "retVal = ShellExecute(..." and the
ShellExecute API declare... and no, I don't have a clue why??? (Wish I
did...:-)
The other thing is that the last parameter on the SHell or SHellExecute does
not seem to have any effect on how the *.msg is displayed....it always comes
up in the Last Position and size...( another I don't know why.... )
The References I have are (Don't know which one's have any effect):
- Visual Basic for applications (MSVBVM60.DLL)
- Visual Basic runtime objects and procedures (MSVBVM60.DLL\3)
- Visual Basic objects and procedures (VB6.OLB)
- Microsoft Scripting runtime (SCRRUN.DLL)
- Microsoft Outlook 9.0 Object Library (MSOUTL9.OLB)
- OLE Automation (STDOLE2.TLB)
I hope all of this makes sense...If not send me a mail and I'll post you the
app that I built, It might not help but it can't hurt.... Regards, Truck.
/************************
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias
"SHellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal nShowCmd As Long) As
Long
Const SW_SHOWNORMAL = 1
/*************************
Function OpenOutLookMail(FileName As String) As Boolean
Dim retVal, aFile
Dim myMail As Outlook.MailItem
Dim sQouteForCMD
sQouteForCMD = Chr(34)
on error goto EndOutLookMail
' Check if any open and close them
Check_Inspectors (olPromptForSave)
/* Uncomment the one that works....
' Shell the file and hope that the OS has the right file type...
'retVal = Shell("cmd /c " & sQouteForCMD & FileName & sQouteForCMD, vbHide)
' Shell the file and hope that the OS has the right file type...
'retVal = ShellExecute(Form1.hWnd, vbNullString, sQouteForCMD & FileName &
sQouteForCMD, "c:\temp", SW_SHOWNORMAL)
' Wait until Inspector is open and CurrentItem is properly initialized
Do
DoEvents
Loop Until Not ActiveInspector Is Nothing
Do
DoEvents
Loop Until Not ActiveInspector.CurrentItem Is Nothing
' Set the object
Set myMail = Application.ActiveInspector.CurrentItem
/*
* The *.msg file should be open and accessible here....
*/
EndOutLookMail:
' Close the one we opened, This closes the *.msg file....
Check_Inspectors (olDiscard)
' Clean-up
Set myMail = Nothing
if err.number > 0 then
msgbox ( "Error #:" & err.number & " Description: " & err.description &
vbcrlf, vbCritical + vbOkOnly, "Mail Error")
end if
End Function
/*************************
Function Check_Inspectors(Prompt As Integer)
Dim Max As Long
Max = Application.Inspectors.Count
If Max > 0 Then
While Application.Inspectors.Count > 0
Application.ActiveInspector.Close (Prompt)
Wend
End If
End Function
/*************************
retVal = Shell("cmd /c " & sQouteForCMD & FileName & _
sQouteForCMD, vbHide)
with sQouteForCMD = Chr(34)
I had tried the Shell-command before - but not with the
right parameter.
I don't "get" the whole Inspector issue though... so I
just don't do it... will that eventually cause me trouble?
John
>.
>
Glad I was some help... :-) The Shell command has issues dealing with long
directory / filenames unless it is enclosed in Quotes...
The inspector thingy just returns an Object so you can get some information
from whatever it is you have opened... It won't cause you any issues....
Regards,
Truck.
"john" <Jo...@nomail.com> wrote in message
news:163101c1d293$301eb9b0$3aef2ecf@TKMSFTNGXA09...