Minggu, 02 Juni 2013

Vedr: [ExcelVBA] Prevent macro from being run twice

 

Thank you for your advices, Dave.

I'll keep it in cells!

Torstein

________________________________
Fra: David Smart <smartware.consulting@gmail.com>
Til: ExcelVBA@yahoogroups.com
Sendt: Lørdag, 1. juni 2013 12.53
Emne: Re: [ExcelVBA] Prevent macro from being run twice


 
> can this be done with a static variable - does it keep
> its value after the sub is run and finished?

Sort of. :-) The static variable will keep its value until Excel decides
to reinitialise the code. This will occur when Excel wants to, not when you
want it to, and will certainly happen each time you open the workbook.

The way to persist information is to put it in cells, as you're doing.

Regards, Dave S

----- Original Message -----
From: "Torstein Johnsen" <sejohnse@yahoo.no>
To: <ExcelVBA@yahoogroups.com>
Sent: Saturday, June 01, 2013 8:24 PM
Subject: [ExcelVBA] Prevent macro from being run twice

I've made a sort of psychological test in excel.

I don't want it to be run more than once.

I have made a range called runbefore, and if the value is greater than zero
the macro ends with a msgbox.

At the start of the sub

sub test()

if range("runbefore").value > 0 then
msgbox("run before")
end
endif
.........

range("runbefore").value =1

end sub

can this be done with a static variable - does it keep its value after the
sub is run and finished?

or

in another way?

regards Torstein

Can this be done with a static variable - does the staic variable keep its
value after the macro has run?

or in another way?

[Non-text portions of this message have been removed]

------------------------------------

----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go
here: http://www.mousetrax.com/techtrax to enter the ezine, then search the
ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------Yahoo! Groups Links

-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1432 / Virus Database: 3184/5873 - Release Date: 05/31/13

[Non-text portions of this message have been removed]

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (7)
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
.

__,_._,___

Tidak ada komentar:

Posting Komentar