ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA Program Won't Run After Auto-Save (https://www.excelbanter.com/excel-programming/383685-excel-vba-program-wont-run-after-auto-save.html)

cebalaw

Excel VBA Program Won't Run After Auto-Save
 
I've been using VBA with Excel since 1995, and have been plagued with a
seemingly random error in every edition I've used. My programs always utilize
forms for entering, manipulating, and reporting data. The actual spreadsheets
are either hidden or minimized. On occasion, I would get the error:

The instruction at "0x00000000" referenced memory at "0x00000000". The
memory could not be "read".

When you step through the program, it works fine. Just when it runs
automatically did the error occur. The fix? I delete the last bit of code
entered; save; re-enter the code EXACTLY as it was before; save. The error
would disappear.

Now my current problem, again I am getting this mysterious error. When the
user closes the main form, the program protects all the worksheets, then
prompts the user to save the program. If you choose yes, it executes the
following lines of code to save the program then closes Excel.

Application.DisplayAlerts = False
ActiveWorkbook.Save
Application.DisplayAlerts = True

When you reopen, it prompts to Enable Macros, but once enabled, it crashes.
To fix the error, I disable macros, save, and all is well.

Anybody have any ideas why this is happening, and better yet, how do i fix
it??

Jim Cone

Excel VBA Program Won't Run After Auto-Save
 

Normally Application.DisplayAlerts is not required when saving a workbook.
It would be used if you were closing the workbook without saving it.

Are there any changes being made to the workbook between saving
and closing it?
Are you sure that the "ActiveWorkbook" is the one you want to save?

A couple of things to try...
First, comment out all of DisplayAlerts code and see what happens.
There may be a surprise alert being displayed that wasn't anticipated.

Second, save and close the workbook using just one line of code:
ActiveWorkbook.Close savechanges:=True
(do this without disabling the Alerts)

Sometimes, all Excel needs is a slightly different way to do something
in order to be happy and content.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"cebalaw"
wrote in message
I've been using VBA with Excel since 1995, and have been plagued with a
seemingly random error in every edition I've used. My programs always utilize
forms for entering, manipulating, and reporting data. The actual spreadsheets
are either hidden or minimized. On occasion, I would get the error:

The instruction at "0x00000000" referenced memory at "0x00000000". The
memory could not be "read".

When you step through the program, it works fine. Just when it runs
automatically did the error occur. The fix? I delete the last bit of code
entered; save; re-enter the code EXACTLY as it was before; save. The error
would disappear.

Now my current problem, again I am getting this mysterious error. When the
user closes the main form, the program protects all the worksheets, then
prompts the user to save the program. If you choose yes, it executes the
following lines of code to save the program then closes Excel.

Application.DisplayAlerts = False
ActiveWorkbook.Save
Application.DisplayAlerts = True

When you reopen, it prompts to Enable Macros, but once enabled, it crashes.
To fix the error, I disable macros, save, and all is well.

Anybody have any ideas why this is happening, and better yet, how do i fix
it??

cebalaw

Excel VBA Program Won't Run After Auto-Save
 
I actually took out the whole auto save and let Excel display the standard
save changes screen, but still if you say yes, it file won't open the next
time (if you enable macros). Its almost as if its not saving the program
properly. I'm at a loss, but its making the program impractical to use.
Having spent so months developing it, I hate to see it go to waste.

"Jim Cone" wrote:


Normally Application.DisplayAlerts is not required when saving a workbook.
It would be used if you were closing the workbook without saving it.

Are there any changes being made to the workbook between saving
and closing it?
Are you sure that the "ActiveWorkbook" is the one you want to save?

A couple of things to try...
First, comment out all of DisplayAlerts code and see what happens.
There may be a surprise alert being displayed that wasn't anticipated.

Second, save and close the workbook using just one line of code:
ActiveWorkbook.Close savechanges:=True
(do this without disabling the Alerts)

Sometimes, all Excel needs is a slightly different way to do something
in order to be happy and content.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"cebalaw"
wrote in message
I've been using VBA with Excel since 1995, and have been plagued with a
seemingly random error in every edition I've used. My programs always utilize
forms for entering, manipulating, and reporting data. The actual spreadsheets
are either hidden or minimized. On occasion, I would get the error:

The instruction at "0x00000000" referenced memory at "0x00000000". The
memory could not be "read".

When you step through the program, it works fine. Just when it runs
automatically did the error occur. The fix? I delete the last bit of code
entered; save; re-enter the code EXACTLY as it was before; save. The error
would disappear.

Now my current problem, again I am getting this mysterious error. When the
user closes the main form, the program protects all the worksheets, then
prompts the user to save the program. If you choose yes, it executes the
following lines of code to save the program then closes Excel.

Application.DisplayAlerts = False
ActiveWorkbook.Save
Application.DisplayAlerts = True

When you reopen, it prompts to Enable Macros, but once enabled, it crashes.
To fix the error, I disable macros, save, and all is well.

Anybody have any ideas why this is happening, and better yet, how do i fix
it??



All times are GMT +1. The time now is 07:51 PM.

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