ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code pause when disconnecting from Terminal Services. (https://www.excelbanter.com/excel-programming/420169-code-pause-when-disconnecting-terminal-services.html)

Trefor

Code pause when disconnecting from Terminal Services.
 
I am running some code on a Windows XP PC using Office 2003 and I am
connecting to this PC via Remote Desktop (Terminal Services). While I am
connected everything appears to be fine, but if I disconnect and leave the
remote PC to run by itself I get issues. This code is in an Excel Module that
processes emails from an Outlook folder, so I am not sure if this is an Excel
issue or an Outlook issue, so I have posted this to both discussion groups.

The problems occurs at the line €œMessageText = olMail.Body€. Initially I
would get a message saying something about waiting for another OLE process,
after some research I found a reference to using €œCoRegisterMessageFilter 0&,
lMsgFilter€ to prevent the message being displayed, this appears to work
fine. BUT if you disconnect from the remote PC when the code gets to the line
in question, it just pauses without error. I have left this for 2 days and it
just sits there, if you then connect back in the code resumes and the code
completes without error. It took me ages to find this single line of code
causing the issue and now that I have found it I have no idea what I can try
next. Any ideas?

Public Declare Function CoRegisterMessageFilter Lib "OLE32.DLL" (ByVal
lFilterIn As Long, ByRef lPreviousFilter) As Long
Public lMsgFilter As Long

For ItemReference = MailCount To 1 Step -1

' Get reference to items in folder
On Error Resume Next

Set olMail = InputFolder.Items(ItemReference)

Application.DisplayAlerts = False
CoRegisterMessageFilter 0&, lMsgFilter

MessageText = olMail.Body <<<<<<< Problem occurs here

Application.DisplayAlerts = True
CoRegisterMessageFilter lMsgFilter, lMsgFilter

joel

Code pause when disconnecting from Terminal Services.
 
Make sure omail isn't returning nothing.

For ItemReference = MailCount To 1 Step -1

' Get reference to items in folder
On Error Resume Next

Set olMail = InputFolder.Items(ItemReference)

if not olMail is nothing then
Application.DisplayAlerts = False
CoRegisterMessageFilter 0&, lMsgFilter

MessageText = olMail.Body <<<<<<< Problem occurs here

Application.DisplayAlerts = True
CoRegisterMessageFilter lMsgFilter, lMsgFilter


"Trefor" wrote:

I am running some code on a Windows XP PC using Office 2003 and I am
connecting to this PC via Remote Desktop (Terminal Services). While I am
connected everything appears to be fine, but if I disconnect and leave the
remote PC to run by itself I get issues. This code is in an Excel Module that
processes emails from an Outlook folder, so I am not sure if this is an Excel
issue or an Outlook issue, so I have posted this to both discussion groups.

The problems occurs at the line €œMessageText = olMail.Body€. Initially I
would get a message saying something about waiting for another OLE process,
after some research I found a reference to using €œCoRegisterMessageFilter 0&,
lMsgFilter€ to prevent the message being displayed, this appears to work
fine. BUT if you disconnect from the remote PC when the code gets to the line
in question, it just pauses without error. I have left this for 2 days and it
just sits there, if you then connect back in the code resumes and the code
completes without error. It took me ages to find this single line of code
causing the issue and now that I have found it I have no idea what I can try
next. Any ideas?

Public Declare Function CoRegisterMessageFilter Lib "OLE32.DLL" (ByVal
lFilterIn As Long, ByRef lPreviousFilter) As Long
Public lMsgFilter As Long

For ItemReference = MailCount To 1 Step -1

' Get reference to items in folder
On Error Resume Next

Set olMail = InputFolder.Items(ItemReference)

Application.DisplayAlerts = False
CoRegisterMessageFilter 0&, lMsgFilter

MessageText = olMail.Body <<<<<<< Problem occurs here

Application.DisplayAlerts = True
CoRegisterMessageFilter lMsgFilter, lMsgFilter
.
.
.
.
Next ItemReference

--
Trefor


Trefor

Code pause when disconnecting from Terminal Services.
 

Joel,

Thankyou for your reply. I can try this, but this does not explain my
symptoms:

1. If I run on my PC, no issues.
2. If I remotely connect to another PC, no issues.
3. If I disconnect from the remote PC, the code stops at €œMessageText =
olMail.Body€
4. If I reconnect to the remote PC, the code will resume without error and
without intervention.

If what you indicate is true, wouldnt it fail all the time?

--
Trefor


"Joel" wrote:

Make sure omail isn't returning nothing.

For ItemReference = MailCount To 1 Step -1

' Get reference to items in folder
On Error Resume Next

Set olMail = InputFolder.Items(ItemReference)

if not olMail is nothing then
Application.DisplayAlerts = False
CoRegisterMessageFilter 0&, lMsgFilter

MessageText = olMail.Body <<<<<<< Problem occurs here

Application.DisplayAlerts = True
CoRegisterMessageFilter lMsgFilter, lMsgFilter


"Trefor" wrote:

I am running some code on a Windows XP PC using Office 2003 and I am
connecting to this PC via Remote Desktop (Terminal Services). While I am
connected everything appears to be fine, but if I disconnect and leave the
remote PC to run by itself I get issues. This code is in an Excel Module that
processes emails from an Outlook folder, so I am not sure if this is an Excel
issue or an Outlook issue, so I have posted this to both discussion groups.

The problems occurs at the line €œMessageText = olMail.Body€. Initially I
would get a message saying something about waiting for another OLE process,
after some research I found a reference to using €œCoRegisterMessageFilter 0&,
lMsgFilter€ to prevent the message being displayed, this appears to work
fine. BUT if you disconnect from the remote PC when the code gets to the line
in question, it just pauses without error. I have left this for 2 days and it
just sits there, if you then connect back in the code resumes and the code
completes without error. It took me ages to find this single line of code
causing the issue and now that I have found it I have no idea what I can try
next. Any ideas?

Public Declare Function CoRegisterMessageFilter Lib "OLE32.DLL" (ByVal
lFilterIn As Long, ByRef lPreviousFilter) As Long
Public lMsgFilter As Long

For ItemReference = MailCount To 1 Step -1

' Get reference to items in folder
On Error Resume Next

Set olMail = InputFolder.Items(ItemReference)

Application.DisplayAlerts = False
CoRegisterMessageFilter 0&, lMsgFilter

MessageText = olMail.Body <<<<<<< Problem occurs here

Application.DisplayAlerts = True
CoRegisterMessageFilter lMsgFilter, lMsgFilter
.
.
.
.
Next ItemReference

--
Trefor


Trefor

Code pause when disconnecting from Terminal Services.
 
Joel,

I made these changes as suggested and it did not make any difference. I note
that if there is no €œoutlook interaction€ required 2 hours worth of
processing goes through unattended without issue. If there are emails to
process and I am not connected the code just stalls until I reconnect.

--
Trefor


"Trefor" wrote:


Joel,

Thankyou for your reply. I can try this, but this does not explain my
symptoms:

1. If I run on my PC, no issues.
2. If I remotely connect to another PC, no issues.
3. If I disconnect from the remote PC, the code stops at €œMessageText =
olMail.Body€
4. If I reconnect to the remote PC, the code will resume without error and
without intervention.

If what you indicate is true, wouldnt it fail all the time?

--
Trefor


"Joel" wrote:

Make sure omail isn't returning nothing.

For ItemReference = MailCount To 1 Step -1

' Get reference to items in folder
On Error Resume Next

Set olMail = InputFolder.Items(ItemReference)

if not olMail is nothing then
Application.DisplayAlerts = False
CoRegisterMessageFilter 0&, lMsgFilter

MessageText = olMail.Body <<<<<<< Problem occurs here

Application.DisplayAlerts = True
CoRegisterMessageFilter lMsgFilter, lMsgFilter


"Trefor" wrote:

I am running some code on a Windows XP PC using Office 2003 and I am
connecting to this PC via Remote Desktop (Terminal Services). While I am
connected everything appears to be fine, but if I disconnect and leave the
remote PC to run by itself I get issues. This code is in an Excel Module that
processes emails from an Outlook folder, so I am not sure if this is an Excel
issue or an Outlook issue, so I have posted this to both discussion groups.

The problems occurs at the line €œMessageText = olMail.Body€. Initially I
would get a message saying something about waiting for another OLE process,
after some research I found a reference to using €œCoRegisterMessageFilter 0&,
lMsgFilter€ to prevent the message being displayed, this appears to work
fine. BUT if you disconnect from the remote PC when the code gets to the line
in question, it just pauses without error. I have left this for 2 days and it
just sits there, if you then connect back in the code resumes and the code
completes without error. It took me ages to find this single line of code
causing the issue and now that I have found it I have no idea what I can try
next. Any ideas?

Public Declare Function CoRegisterMessageFilter Lib "OLE32.DLL" (ByVal
lFilterIn As Long, ByRef lPreviousFilter) As Long
Public lMsgFilter As Long

For ItemReference = MailCount To 1 Step -1

' Get reference to items in folder
On Error Resume Next

Set olMail = InputFolder.Items(ItemReference)

Application.DisplayAlerts = False
CoRegisterMessageFilter 0&, lMsgFilter

MessageText = olMail.Body <<<<<<< Problem occurs here

Application.DisplayAlerts = True
CoRegisterMessageFilter lMsgFilter, lMsgFilter
.
.
.
.
Next ItemReference

--
Trefor



All times are GMT +1. The time now is 12:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com