On Wed, 12 Dec 2007 20:28:00 -0800, David Nebenzahl wrote:
> This is a really annoying problem: I have a worksheet with a macro I
> wrote to do some reformatting on one of the sheets before I submit it as
> a CSV file to a database. I set up a button on the toolbar linked to the
> macro: when I open the file, move my data to this one sheet and click
> the button, the macro runs as it should.
>
> I then save that sheet as a CSV file; I basically say "no" to all the
> warning alerts that pop up, warning me that in that format it's only
> possible to save that particular sheet (which is the only one I'm
> interested in for that purpose anyhow), etc. The CSV file gets created
> correctly. Then I just abandon the now-CSV workbook. Fine.
>
> The problem is that the next time I open the Excel version of the
> workbook (which was NOT saved in its altered state), I cannot run the
> macro by using the toolbar button: I get an error message saying it
> can't find <mumbo-jumbo ... macro-name>.CSV. Even weirder, it also opens
> the CSV file at the same time. (I can run the macro by invoking it
> through the Tools menu, but the button is intended to make this whole
> process easy for non-computer-literate types, and this defeats that
> purpose.)
>
> When I delete the CSV file, which is only needed temporarily, then
> things get even uglier: Excel complains that it can't find the CSV file
> when I'm working with the normal (XLS) version of the workbook.
>
> Is there some way to get Excel to disassociate or disentangle itself
> from this CSV file so I don't run into all these problems? It seems that
> only a system reboot makes the XLS file usable again.
My advice is not to use a macro to do this at all. Take your macro code
and translate it to a vbscript 'scripting macro'. Each time you want to
run the macro, you actually run the script, which opens the workbook and
does all the work with it - but does not actually put any code in the
workbook its self. IE separate model and controller.
In general, it is getting ever harder to use macros inside workbooks with
Excel, so I developed the concept of 'scripting macros' for just this
sort of problem which I hit constantly at work.
See my blog or book.
http://nerds-central.blogspot.com and click on the
label for 'baby steps' or Exsead.
AJ
--
http://nerds-central.blogspot.com/20...-become-excel-
god.html