View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Nick Nick is offline
external usenet poster
 
Posts: 39
Default Problem with a macro

I think I had a similar problem where the readonly status
of the file was changed during the execution of the macro.

This then caused problems including a memory access
violation.

I suggest you save the newly created workbook before
making changes and then aftewards.

This may not be relevant but I hope it helps

Nick


-----Original Message-----
I have a strange problem with some macros in Excel 2000.

The macros are all run from buttons on the same

worksheet. This
worksheet allows the user to select a client name from a

drop-down
list, then builds a path/filename based on that selection.

Once the path/filename is built, the user can press

another button to
actually load a file into Excel (it is an excel

workbook). This macro
uses the code "Workbooks.Open m_file" to load the

workbook, where
m_file contains the path/filename generated earlier.

This part works
fine.

Once the file is loaded, there is another button which

runs a macro to
compare a list of names in the current workbook against a

master list
in another workbook. If there are names to be added, the

macro inserts
a row in the proper place and copys the information from

the master
list.

I am using "Selection.EntireRow.Insert" to insert the row

(the
currently selected row is at the position where I want

the row
inserted).

This code causes a memory access violation and crashes

Excel, but
here's the strange part. This crash happens *only* if

the file was
loaded by clicking the "load" button mentioned earlier.

If the user selects the client name from the list (so the

filename gets
built), but then goes out and loads the file manually

without clicking
the "Load file" button, then when the "Update Rows"

button is clicked,
there is no crash. The macro works fine and inserts rows

as needed,
often multiple times in the same run. Running the Update

macro after
the file has been loaded by clicking the Load button

results in a fatal
crash every single time the EntireRow.Insert code fires.

Anyone have any ideas why this could be happening?


---
Message posted from http://www.ExcelForum.com/

.