Access the WordEditor object in Outlook VBA

I need to install a Word Add-in in the Word application in Outlook (using Word as editor in Outlook 2003). I have the code below, but it didn't work - I don't have any inspectors on startup.

Please help me make my code run.
Private Sub Application_Startup()
    Set myInspector = Item.GetInspector
    Set worddoc = myInspector.WordEditor
    worddoc.AddIns.Add FileName:="addin.dot", Install:=True
End Sub

Open in new window

thor_ostergaardAsked:
Who is Participating?
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Honest answer I don't know a streamlined way to do this, as a kludge have you tried opening word as the first activitiy in the outlook startup?

Dim wd As Object
    Set wd = CreateObject("word.application")
    wd.Visible = True

Alternatively assuming the general syntax of your initial post is corrrect and the inbox does have at least 1 item  then perhaps:

Chris
Private Sub Application_Startup() 
    Set myInspector = application.session.getdefaultfolder(olfolderinbox).items(1).GetInspector 
    Set worddoc = myInspector.WordEditor 
    worddoc.AddIns.Add FileName:="addin.dot", Install:=True
End Sub

Open in new window

0
 
peakpeakCommented:
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Hello thor_ostergaard,

Private Sub Application_Startup()
    Set myInspector = Item.GetInspector

The sub is run at startup and as such there is no item instantiated therefore the assignment fails.

Basically the inspector will associate to a mailitem in this instance so until you which mailitem to work upon the script is 'stumped'/

Regards,

chris_bottomley
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
thor_ostergaardAuthor Commented:
I know - but I can see Word is starting with Outlook (before any mail items are created).
Is there a way I can access that Word instance without creating a mail item?
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Not that I know of ... but it ought not be necessary to create an item you can latch onto an existing item.

More importantly though what are you trying to achieve and perhaps that spec ific can be addressed?

Chris
0
 
thor_ostergaardAuthor Commented:
In my Word startup folder I have an add-in with some code in it (in this case the code installs another add-in, but that's not important).
If I start Outlook before Word the code in my add-in don't get executed - and starting Word after Outlook didn't execute the code either. Therefore I will have a copy of the code from the add-in in Outlook to make sure the code gets executed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.