problems when opening Excel from ACAD

  • Thread starter Thread starter mtechserv
  • Start date Start date
M

mtechserv

I've written an AutoCAD VBA program that is activated from a toolbar button in ACAD. It retrieves info. from the drawing, then opens Excel and writes the drawing info to Excel. The program works fine the first time I use it. Then I close Excel, and try to run the program from AutoCAD again, but it crashes after Excel opens, but before it writes the data to the spreadsheet.
In order to run the program again without crashing, I need to go into the VBA editor, and reset the program. It wil then work fine one time, then crashes again the second time until I reset everything.
It appears as though it doesn't release the ActiveSheet member. How do I fix this?
 
You've got to make sure you've Closed/Released/Set = Nothing, all that stuff, for each Excel object you've referenced in your code.
 
Besides the other posts, you may consider using ADO/DAO to access data in
*.xls file (read/write). It is faster than automating Excel. You do not even
need to have Excel installed.

mtechserv said:
I've written an AutoCAD VBA program that is activated from a toolbar
button in ACAD. It retrieves info. from the drawing, then opens Excel and
writes the drawing info to Excel. The program works fine the first time I
use it. Then I close Excel, and try to run the program from AutoCAD again,
but it crashes after Excel opens, but before it writes the data to the
spreadsheet.
In order to run the program again without crashing, I need to go into the
VBA editor, and reset the program. It wil then work fine one time, then
crashes again the second time until I reset everything.
It appears as though it doesn't release the ActiveSheet member. How do I
fix this?
 
You've got to make sure you've Closed/Released/Set = Nothing, all that stuff, for each Excel object you've referenced in your code.

More than that, they have to be done in the exact reverse order you used to
create them --- cells/ranges/worksheet/workbook/object

-- Mike
___________________________
Mike Tuersley
CADalyst's CAD Clinic
Rand IMAGINiT Technologies
___________________________
the trick is to realize that there is no spoon...
 
Yeah, I figured that to be a given. But still a good idea to mention it.
 
Back
Top