Run macro at open

K

KJ

I have a particular easy macro I created that runs when I open a quote
workbook.
I have a separate workbook where I log all my quotes with quote numbers. On
my "Blank Quote" workbook I have a cell (out of the print area) that returns
the highest quote number listed from my "Log" file. I have another cell next
to it that takes that highest quote number and adds "1". Thus giving me my
next available quote number.

The macro I created copies that next available quote number, copies, and
pastes it as a value in the print area in my Quote number field. The idea was
that after I save my "Blank Quote" workbook as a quote number (ei Quote 150)
I could re-open my quote number 150 at a later date and always have the quote
number field return "150". Before I was just manually typing it.

I wasn't thinking ahead. Everytime I re-open quote "150", it runs the macro
again. If I've done other quotes since then, it changes the quote number to
whatever the highest number is again, plus 1.

Question: Can I save as, and not carry over this macro? Or is there another
way to accomplish my end goal?

Any help would be greatly appreciated!! FYI, I'm running 2007, but save most
everything in the 97-2000 compatible format so they can be used by others.
Also, creating this macro to run at the open workbook stage is the most
advanced vba thing I've ever done.

Thanks everybody!! Ken.
 
G

Gary''s Student

You are in control when you open the file. If you want the macro to run,
open it normally. If you don't want the macro to run, open it in Office Safe
Mode.
 
D

Dave Peterson

You can use code from Chip Pearson's site to remove your code--but it's subject
to the user's security settings.

http://cpearson.com/excel/vbe.aspx

Maybe easier would be to check the name of the file before you do the real work:

If you're using the Auto_Open procedure:

if lcase(thisworkbook.name) = lcase("blank quote") then
'do the work
end if

If you're using the Workbook_Open event:

if lcase(me.name) = lcase("blank quote") then
'do the work
end if

Other options would be to check the .FullName (which includes the path) or the
..Path itself.

And maybe you could even check a cell that's empty in the master, but completed
in the "real" workbook.

if isempty(thisworkbook.worksheets("sheet999").range("a1")) then
'do the work
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top