Macros don’t run unattended

L

Lionel H

Macros don’t run unattended

Software involved is Windows XP/Outlook/Excel 2003
Moving to 2007 is not currently an option.
OL security is set to Low.
All code is self certified.
I use Windows scheduled tasks to start an OL session followed a minute later
by an XL session

If I remain logged in to the computer while the scheduled tasks fire up, the
OL & XL code executes as I expect.
If I log out of the computer before the scheduled tasks fire up, OL code
does not execute at all; XL code executes as far as it can until it hangs
waiting for OL to do something.

A previous discussion item suggests that this can be fixed by inhibiting
splash screens, but wide ranging searches on Google suggest that almost all
splash screens can be inhibited except for the OL splash screen.

The OL code involved is below.
The trace logs for attended and unattended running are below that.
What the XL code does is immaterial to this question.

Can anyone help either with OL splash screen inhibition or any other way of
persuading the OL code to execute in “unattended†mode?


In ThisOutlookSession:

Option Explicit
Dim objX As Object

Private Sub Application_Startup()
Set objX = New olEventClassModule
Log_RB_Trace_Line "I", "Application_Startup", "OL Started"
End Sub

Private Sub Application_Quit()
Set objX = Nothing
Log_RB_Trace_Line "I", "Application_Quit", "OL Ended"
End Sub

In Class Modules olEventClassModule:

Option Explicit

Dim myolApp As New Outlook.Application
Dim myNS As NameSpace
Dim myServerMailbox As Outlook.MAPIFolder
Dim WithEvents myServerMailboxFolders As Outlook.Folders


Private Sub Class_Initialize()
Set myNS = myolApp.GetNamespace("MAPI")
Set myServerMailbox = myNS.Folders("<mailbox name>") 'edited to remove
real name
Set myServerMailboxFolders = myServerMailbox.Folders

End Sub

Private Sub myServerMailboxFolders_FolderChange(ByVal Folder As MAPIFolder)

Log_RB_Trace_Line "I", "myServerMailboxFolders_FolderChange", "OL " &
Folder & " changed"

Select Case Folder
Case "Drafts"
If Folder.Items.Count = 0 Then
Log_RB_Trace_Line "I",
"myServerMailboxFolders_FolderChange", "OL Application Quit"
Application.Quit
End If
Case Else
'do nothing
End Select
End Sub

In Modules M06_Utilities:

Option Explicit

Sub Log_RB_Trace_Line(strLineType As String, strModuleName As String,
strLine As String)

Open "D:\RB_Trace_Log.txt" For Append As #1
Write #1, Now() & " OL: " & strLineType & ": " & strModuleName & ": " &
strLine
Close #1

End Sub

Trace logged by “attended†run

"20/03/2009 16:14:12 OL: I: Application_Startup: OL Started"
"20/03/2009 16:14:40 XL: I: M41_ReCreate_Peak_Status: Start"
"20/03/2009 16:15:06 XL: I: M41_ReCreate_Peak_Status: PeakStatus.xls saved"
"20/03/2009 16:15:06 XL: I: M07_Publish_File_on_ProjectWEB: Start"
"20/03/2009 16:15:06 XL: I: M07_New_Send_olMailItem: Start"
"20/03/2009 16:15:07 OL: I: myServerMailboxFolders_FolderChange: OL Drafts
changed"
"20/03/2009 16:15:07 XL: I: M07_New_Send_olMailItem:
D:\Pathway\XL_Workbooks\ReleaseBoard\PeakStatus.xls Sent"
"20/03/2009 16:15:07 XL: I: M41_ReCreate_Peak_Status: File Published"
"20/03/2009 16:15:07 XL: I: M41_ReCreate_Peak_Status: XL Quit"
"20/03/2009 16:15:26 OL: I: myServerMailboxFolders_FolderChange: OL Drafts
changed"
"20/03/2009 16:15:26 OL: I: myServerMailboxFolders_FolderChange: OL
Application Quit"
"20/03/2009 16:15:31 OL: I: Application_Quit: OL Ended"


Trace logged by “unattended†run

"20/03/2009 16:23:00 XL: I: M41_ReCreate_Peak_Status: Start"
"20/03/2009 16:23:26 XL: I: M41_ReCreate_Peak_Status: PeakStatus.xls saved"
"20/03/2009 16:23:26 XL: I: M07_Publish_File_on_ProjectWEB: Start"
"20/03/2009 16:23:26 XL: I: M07_New_Send_olMailItem: Start"
 
K

Ken Slovak - [MVP - Outlook]

What do you mean by "remain logged into the computer"? Do you mean logging
off the Windows logon session? If so just don't do that.

Where is the code in the Class Modules olEventClassModule, is it in the
Outlook VBA project? If so do not use New Outlook.Application, use the
intrinsic Outlook.Application object Application instead.
 
L

Lionel H

Ken,

Being logged in or out of the computer is a red herring - which is
fortunate, because that is a story the technicalities of which would very
quickly defeat me.

Your advice about using the intrinsic Outlook.Application object Application
did the trick – thank you, I would not have got there without it.

XL hanging had nothing to do with OL hanging, and if my XL error management
had been more robust, I’d have known that. Still it goes some way to
explaining why I’ve taken so long to get back to you.

Once again, many thanks.

Lionel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top