How to handle the exception that user quite the Outlook while VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Experts,
I screw up on handling the exception that user quite the Outlook while VBA
is still running. This normally does not happen so I never thought it before.
But now my program in Outlook is triggered by a timer at a fixed interval,
its operations are invisible to the outlook user. hence very possible that
the user close the Outlook when the program is still running the code. This
would cause the operations uncompleted and causing big trouble. Is there
something like transatcions in database so I can roll back each operation
when such exception happens.

Please give me some hints how to solve such problem.I would appreciat your
help a lot.

Thanks very much and Regards
Shu
 
No, Outlook doesn't support a transactional data model.

I would redesign your solution so that your custom operations are linked to
any of the events exposed by the Object Model. This approach is user-driven,
and would be more stable than having your application doing whatever it wants
without knowing what the user could be doing at any given time, which is a
recipe for disaster.
 
Hi Eric,
Thanks very much for the suggestions. I wanted to completely automate the
operations, but it seems this is impossible on the client side.

Thanks again and regards,
Shu

Eric Legault [MVP - Outlook]"
 
What is it exactly that you are automating?

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


VBA question said:
Hi Eric,
Thanks very much for the suggestions. I wanted to completely automate the
operations, but it seems this is impossible on the client side.

Thanks again and regards,
Shu

Eric Legault [MVP - Outlook]"
No, Outlook doesn't support a transactional data model.

I would redesign your solution so that your custom operations are linked to
any of the events exposed by the Object Model. This approach is user-driven,
and would be more stable than having your application doing whatever it wants
without knowing what the user could be doing at any given time, which is a
recipe for disaster.
 
Hi Eric,
The operations I want to automate are:
1. Save an Exel attachment of a mail item.
2. Read an Exel database file to get the current largest reference number,
plus one as the reference number of the mail.
3. Save the new reference number to the Excel database file.
4. Set the UserProperty of the mail as "read".
5. Sent back a confirmation letter with the reference number.

If my program stopped at operation 3, then next time the program start
again, the same mail item is read again and set another new reference number,
which is a disaster for the application.

My old design is using a timer to run those operations automatically, but
ignoring the case that the user can close the Outlook and stop the program at
any time. If I add an command button to let user click then run the program
as you suggested, then such exception become much less.

However, the solution still does not prevent the problem completely. In the
case of the computer is shut down for some other reason like hardware
problem, such exception still could happen.

Do you have any other good ideas?

Thanks very much.
Shu

“Eric Legault [MVP - Outlook]â€
What is it exactly that you are automating?

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


VBA question said:
Hi Eric,
Thanks very much for the suggestions. I wanted to completely automate the
operations, but it seems this is impossible on the client side.

Thanks again and regards,
Shu

Eric Legault [MVP - Outlook]"
No, Outlook doesn't support a transactional data model.

I would redesign your solution so that your custom operations are linked to
any of the events exposed by the Object Model. This approach is user-driven,
and would be more stable than having your application doing whatever it wants
without knowing what the user could be doing at any given time, which is a
recipe for disaster.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


:

Hi Experts,
I screw up on handling the exception that user quite the Outlook while VBA
is still running. This normally does not happen so I never thought it before.
But now my program in Outlook is triggered by a timer at a fixed interval,
its operations are invisible to the outlook user. hence very possible that
the user close the Outlook when the program is still running the code. This
would cause the operations uncompleted and causing big trouble. Is there
something like transatcions in database so I can roll back each operation
when such exception happens.

Please give me some hints how to solve such problem.I would appreciat your
help a lot.

Thanks very much and Regards
Shu
 
Your users *shouldn't* be able to shut down Outlook while your code is
running, unless it is a very lengthy operation. However, I'm not quite sure
if Outlook will wait for a macro or Add-In to complete before completing it's
shut down process. And regardless of the application or solution, there's
not much a developer can do to handle OS or hardware failure.

If running your Excel automation code via user intervention (clicking a
button) is not what you'd like, think about when a user may be doing
something that makes sense for this code to execute, like opening an e-mail
(Item_Open), saving (Item_Save) or sending (Item_Send). These and other
events could be handy hooks to launch your custom process.

--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


VBA question said:
Hi Eric,
The operations I want to automate are:
1. Save an Exel attachment of a mail item.
2. Read an Exel database file to get the current largest reference number,
plus one as the reference number of the mail.
3. Save the new reference number to the Excel database file.
4. Set the UserProperty of the mail as "read".
5. Sent back a confirmation letter with the reference number.

If my program stopped at operation 3, then next time the program start
again, the same mail item is read again and set another new reference number,
which is a disaster for the application.

My old design is using a timer to run those operations automatically, but
ignoring the case that the user can close the Outlook and stop the program at
any time. If I add an command button to let user click then run the program
as you suggested, then such exception become much less.

However, the solution still does not prevent the problem completely. In the
case of the computer is shut down for some other reason like hardware
problem, such exception still could happen.

Do you have any other good ideas?

Thanks very much.
Shu

“Eric Legault [MVP - Outlook]â€
What is it exactly that you are automating?

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


VBA question said:
Hi Eric,
Thanks very much for the suggestions. I wanted to completely automate the
operations, but it seems this is impossible on the client side.

Thanks again and regards,
Shu

Eric Legault [MVP - Outlook]"

No, Outlook doesn't support a transactional data model.

I would redesign your solution so that your custom operations are linked to
any of the events exposed by the Object Model. This approach is user-driven,
and would be more stable than having your application doing whatever it wants
without knowing what the user could be doing at any given time, which is a
recipe for disaster.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


:

Hi Experts,
I screw up on handling the exception that user quite the Outlook while VBA
is still running. This normally does not happen so I never thought it before.
But now my program in Outlook is triggered by a timer at a fixed interval,
its operations are invisible to the outlook user. hence very possible that
the user close the Outlook when the program is still running the code. This
would cause the operations uncompleted and causing big trouble. Is there
something like transatcions in database so I can roll back each operation
when such exception happens.

Please give me some hints how to solve such problem.I would appreciat your
help a lot.

Thanks very much and Regards
Shu
 
Hi Eric,
I am sure Outlook does not wait for a macro to complete before shutdown
since I did the test. Is there any way to prevent the shutdown appropriately
by users? For example, like the way when users try to close a Excel file. If
the file is not saved, it will provide the user second chance to decide
whether close it with or without saving.

I appreciate your time a lot.

Regards
Shu

“Eric Legault [MVP - Outlook]â€ç¼–写:
Your users *shouldn't* be able to shut down Outlook while your code is
running, unless it is a very lengthy operation. However, I'm not quite sure
if Outlook will wait for a macro or Add-In to complete before completing it's
shut down process. And regardless of the application or solution, there's
not much a developer can do to handle OS or hardware failure.

If running your Excel automation code via user intervention (clicking a
button) is not what you'd like, think about when a user may be doing
something that makes sense for this code to execute, like opening an e-mail
(Item_Open), saving (Item_Save) or sending (Item_Send). These and other
events could be handy hooks to launch your custom process.

--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


VBA question said:
Hi Eric,
The operations I want to automate are:
1. Save an Exel attachment of a mail item.
2. Read an Exel database file to get the current largest reference number,
plus one as the reference number of the mail.
3. Save the new reference number to the Excel database file.
4. Set the UserProperty of the mail as "read".
5. Sent back a confirmation letter with the reference number.

If my program stopped at operation 3, then next time the program start
again, the same mail item is read again and set another new reference number,
which is a disaster for the application.

My old design is using a timer to run those operations automatically, but
ignoring the case that the user can close the Outlook and stop the program at
any time. If I add an command button to let user click then run the program
as you suggested, then such exception become much less.

However, the solution still does not prevent the problem completely. In the
case of the computer is shut down for some other reason like hardware
problem, such exception still could happen.

Do you have any other good ideas?

Thanks very much.
Shu

“Eric Legault [MVP - Outlook]â€
What is it exactly that you are automating?

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


:

Hi Eric,
Thanks very much for the suggestions. I wanted to completely automate the
operations, but it seems this is impossible on the client side.

Thanks again and regards,
Shu

Eric Legault [MVP - Outlook]"

No, Outlook doesn't support a transactional data model.

I would redesign your solution so that your custom operations are linked to
any of the events exposed by the Object Model. This approach is user-driven,
and would be more stable than having your application doing whatever it wants
without knowing what the user could be doing at any given time, which is a
recipe for disaster.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


:

Hi Experts,
I screw up on handling the exception that user quite the Outlook while VBA
is still running. This normally does not happen so I never thought it before.
But now my program in Outlook is triggered by a timer at a fixed interval,
its operations are invisible to the outlook user. hence very possible that
the user close the Outlook when the program is still running the code. This
would cause the operations uncompleted and causing big trouble. Is there
something like transatcions in database so I can roll back each operation
when such exception happens.

Please give me some hints how to solve such problem.I would appreciat your
help a lot.

Thanks very much and Regards
Shu
 
If you have a handle to an e-mail item that you've hooked into from your VBA
project (or another Office app, or VB6, etc.), then you can control some
things that the user does with events. In your case, you can trap the
Item_Close event and *cancel* it if you can introduce some logic (e.g. Excel
file not in desired state) that tells you whether it is safe to close or not.

However, you cannot cancel the Application_Quit event (fired when Outlook
closes), which is actually quite useless. You also cannot cancel the Close
event with VBScript if you are using a custom form.

If you want more info on hooking into e-mail items, see my article about
this on my blog:

Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/articles/2224.aspx

--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


VBA question said:
Hi Eric,
I am sure Outlook does not wait for a macro to complete before shutdown
since I did the test. Is there any way to prevent the shutdown appropriately
by users? For example, like the way when users try to close a Excel file. If
the file is not saved, it will provide the user second chance to decide
whether close it with or without saving.

I appreciate your time a lot.

Regards
Shu

“Eric Legault [MVP - Outlook]â€ç¼–写:
Your users *shouldn't* be able to shut down Outlook while your code is
running, unless it is a very lengthy operation. However, I'm not quite sure
if Outlook will wait for a macro or Add-In to complete before completing it's
shut down process. And regardless of the application or solution, there's
not much a developer can do to handle OS or hardware failure.

If running your Excel automation code via user intervention (clicking a
button) is not what you'd like, think about when a user may be doing
something that makes sense for this code to execute, like opening an e-mail
(Item_Open), saving (Item_Save) or sending (Item_Send). These and other
events could be handy hooks to launch your custom process.

--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


VBA question said:
Hi Eric,
The operations I want to automate are:
1. Save an Exel attachment of a mail item.
2. Read an Exel database file to get the current largest reference number,
plus one as the reference number of the mail.
3. Save the new reference number to the Excel database file.
4. Set the UserProperty of the mail as "read".
5. Sent back a confirmation letter with the reference number.

If my program stopped at operation 3, then next time the program start
again, the same mail item is read again and set another new reference number,
which is a disaster for the application.

My old design is using a timer to run those operations automatically, but
ignoring the case that the user can close the Outlook and stop the program at
any time. If I add an command button to let user click then run the program
as you suggested, then such exception become much less.

However, the solution still does not prevent the problem completely. In the
case of the computer is shut down for some other reason like hardware
problem, such exception still could happen.

Do you have any other good ideas?

Thanks very much.
Shu

“Eric Legault [MVP - Outlook]â€
What is it exactly that you are automating?

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


:

Hi Eric,
Thanks very much for the suggestions. I wanted to completely automate the
operations, but it seems this is impossible on the client side.

Thanks again and regards,
Shu

Eric Legault [MVP - Outlook]"

No, Outlook doesn't support a transactional data model.

I would redesign your solution so that your custom operations are linked to
any of the events exposed by the Object Model. This approach is user-driven,
and would be more stable than having your application doing whatever it wants
without knowing what the user could be doing at any given time, which is a
recipe for disaster.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


:

Hi Experts,
I screw up on handling the exception that user quite the Outlook while VBA
is still running. This normally does not happen so I never thought it before.
But now my program in Outlook is triggered by a timer at a fixed interval,
its operations are invisible to the outlook user. hence very possible that
the user close the Outlook when the program is still running the code. This
would cause the operations uncompleted and causing big trouble. Is there
something like transatcions in database so I can roll back each operation
when such exception happens.

Please give me some hints how to solve such problem.I would appreciat your
help a lot.

Thanks very much and Regards
Shu
 
Many Thanks for your time, Eric.

Regards
Shu
“Eric Legault [MVP - Outlook]â€ç¼–写:
If you have a handle to an e-mail item that you've hooked into from your VBA
project (or another Office app, or VB6, etc.), then you can control some
things that the user does with events. In your case, you can trap the
Item_Close event and *cancel* it if you can introduce some logic (e.g. Excel
file not in desired state) that tells you whether it is safe to close or not.

However, you cannot cancel the Application_Quit event (fired when Outlook
closes), which is actually quite useless. You also cannot cancel the Close
event with VBScript if you are using a custom form.

If you want more info on hooking into e-mail items, see my article about
this on my blog:

Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/articles/2224.aspx

--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


VBA question said:
Hi Eric,
I am sure Outlook does not wait for a macro to complete before shutdown
since I did the test. Is there any way to prevent the shutdown appropriately
by users? For example, like the way when users try to close a Excel file. If
the file is not saved, it will provide the user second chance to decide
whether close it with or without saving.

I appreciate your time a lot.

Regards
Shu

“Eric Legault [MVP - Outlook]â€ç¼–写:
Your users *shouldn't* be able to shut down Outlook while your code is
running, unless it is a very lengthy operation. However, I'm not quite sure
if Outlook will wait for a macro or Add-In to complete before completing it's
shut down process. And regardless of the application or solution, there's
not much a developer can do to handle OS or hardware failure.

If running your Excel automation code via user intervention (clicking a
button) is not what you'd like, think about when a user may be doing
something that makes sense for this code to execute, like opening an e-mail
(Item_Open), saving (Item_Save) or sending (Item_Send). These and other
events could be handy hooks to launch your custom process.

--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


:

Hi Eric,
The operations I want to automate are:
1. Save an Exel attachment of a mail item.
2. Read an Exel database file to get the current largest reference number,
plus one as the reference number of the mail.
3. Save the new reference number to the Excel database file.
4. Set the UserProperty of the mail as "read".
5. Sent back a confirmation letter with the reference number.

If my program stopped at operation 3, then next time the program start
again, the same mail item is read again and set another new reference number,
which is a disaster for the application.

My old design is using a timer to run those operations automatically, but
ignoring the case that the user can close the Outlook and stop the program at
any time. If I add an command button to let user click then run the program
as you suggested, then such exception become much less.

However, the solution still does not prevent the problem completely. In the
case of the computer is shut down for some other reason like hardware
problem, such exception still could happen.

Do you have any other good ideas?

Thanks very much.
Shu

“Eric Legault [MVP - Outlook]â€
What is it exactly that you are automating?

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


:

Hi Eric,
Thanks very much for the suggestions. I wanted to completely automate the
operations, but it seems this is impossible on the client side.

Thanks again and regards,
Shu

Eric Legault [MVP - Outlook]"

No, Outlook doesn't support a transactional data model.

I would redesign your solution so that your custom operations are linked to
any of the events exposed by the Object Model. This approach is user-driven,
and would be more stable than having your application doing whatever it wants
without knowing what the user could be doing at any given time, which is a
recipe for disaster.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--
Try Picture Attachments Wizard for Outlook!
http://tinyurl.com/9bby8
--
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


:

Hi Experts,
I screw up on handling the exception that user quite the Outlook while VBA
is still running. This normally does not happen so I never thought it before.
But now my program in Outlook is triggered by a timer at a fixed interval,
its operations are invisible to the outlook user. hence very possible that
the user close the Outlook when the program is still running the code. This
would cause the operations uncompleted and causing big trouble. Is there
something like transatcions in database so I can roll back each operation
when such exception happens.

Please give me some hints how to solve such problem.I would appreciat your
help a lot.

Thanks very much and Regards
Shu
 
Back
Top