View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Matt[_49_] Matt[_49_] is offline
external usenet poster
 
Posts: 3
Default Excel crashes when I add VBA code programatically

The code that is performing the update does not reside in the same
module, but is part of the same VB project. This is really kind of
the intent as I essentially want users to be working with the latest
code without having to go somewhere else to get the update. I suppose
I could make the Update procedure an add-in but that would then
require my users to install something else and it defeats the purpose
to some extent.

As it's working right now, the code that is running the update is
completely untouched by the update itself. It's iterating through a
fixed list of modules, deleting all the lines in the CodeModule, then
adding the code back into this set list of modules via a string
returned from the XML web service. Again, this is working for some of
my modules and Excel is crashing on others. If I remove the modules
that cause Excel to crash, the process works. Would Excel crash
because there are references to classes or types I have defined or
could whitespace cause it? Would Excel crash because the code cannot
be compiled until all of the code is added back in? Speaking of
which, is there a way recompile the code once it's added back in?
Would Excel crash because there are cells in the workbook that are
calling functions from VBA that are deleted and then added back in?

Thank you for your help.

Matt

On May 19, 4:03*pm, "Chip Pearson" wrote:
Does the code that performs the updates reside in the same module as the
code being inserted? *In other words, is a module attempting to modify
itself? *I would STRONGLY recommend against doing so. *If you have the time,
you might consider moving the code that performs the updates out of the
VBProject and into another project, so that no part of a project is
attempting to modify any (other) part of the same project. A project should
only update another project, not itself.

--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
* * Excel Product Group
Pearson Software Consulting, LLCwww.cpearson.com
(email on web site)

wrote in message

...



I've written an XML web service to check the version of the VBA in an
Excel file against the version stored in the database. *If the version
in the database is newer, the user is asked if they want to update
their file. *If so, the web service returns the stored code from a
CLOB in the database and passes it to VBA as a string. *After deleting
all of the lines of code in the appropriate VBA module, it writes the
new code back into the Code Module as follows:


ThisWorkbook.VBProject.VBComponents.item(sCodeName ).CodeModule.AddFromStrin*g
s


As it iterates through all of the appropriate forms, modules and
classes to update, I always get a "Microsoft Office Excel has
encountered a problem and needs to close" message...


This is working for SOME of my code. *But failing consistently on
certain modules. *I cannot make a distinction between the modules that
are working vs. the ones that are not.


Am I missing something? *Has anyone seen anything like this? *Anyone
have any ideas of what could be causing Excel to crash or want to see
more code?


Thank you in advance.- Hide quoted text -


- Show quoted text -