Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Verify before proceeding
Hello, Is there a way that I can check to see if a macro was run from within that macro before it proceeds with a part of the macro, maybe have it check something before proceeding with the rest of it ? What I want it to do is stop someone from run a macro again if it was already ran, and if it wasn't ran before to check some column headings to make sure they are all there, before proceeding with the macro. Thanks -- snowing ------------------------------------------------------------------------ snowing's Profile: http://www.excelforum.com/member.php...o&userid=34576 View this thread: http://www.excelforum.com/showthread...hreadid=547810 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Verify before proceeding
Dim bMacro1WasRun as boolean
sub MySub() if bMacro1WasRun then <do something else <do whatever end if end sub sub Macro1 <do some stuff bMacro1WasRun = true end sub Et voilà -- AP "snowing" a écrit dans le message de news: ... Hello, Is there a way that I can check to see if a macro was run from within that macro before it proceeds with a part of the macro, maybe have it check something before proceeding with the rest of it ? What I want it to do is stop someone from run a macro again if it was already ran, and if it wasn't ran before to check some column headings to make sure they are all there, before proceeding with the macro. Thanks -- snowing ------------------------------------------------------------------------ snowing's Profile: http://www.excelforum.com/member.php...o&userid=34576 View this thread: http://www.excelforum.com/showthread...hreadid=547810 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Verify before proceeding
There are various ways of doing this but I think the easiest way is to use a cell on a worksheet (maybe a hidden sheet) to store an update/updated flag. Then use the workbook.open event to set the flag to "update". Before running the checking macro see if the is "update" Then when you run the macro which does the update reset the flag to "updated". Note that if you try and hold the flag as a variable it will get reset each time the code finishes. regards -- tony h ------------------------------------------------------------------------ tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074 View this thread: http://www.excelforum.com/showthread...hreadid=547810 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Verify before proceeding
Thanks for the help. Ardus can you explain your code a little for me, I would need something to work from within the one macro -- snowing ------------------------------------------------------------------------ snowing's Profile: http://www.excelforum.com/member.php...o&userid=34576 View this thread: http://www.excelforum.com/showthread...hreadid=547810 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Verify before proceeding
Tony's solution is smarter because it saves the "MacroWasRun" status
You place a FALSE/TRUE value in some definite cell, then you test its contents. HTH -- AP "snowing" a écrit dans le message de news: ... Hello, Is there a way that I can check to see if a macro was run from within that macro before it proceeds with a part of the macro, maybe have it check something before proceeding with the rest of it ? What I want it to do is stop someone from run a macro again if it was already ran, and if it wasn't ran before to check some column headings to make sure they are all there, before proceeding with the macro. Thanks -- snowing ------------------------------------------------------------------------ snowing's Profile: http://www.excelforum.com/member.php...o&userid=34576 View this thread: http://www.excelforum.com/showthread...hreadid=547810 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Verify before proceeding
Here is some code that does not use a cell for storage but one of th document properties - if necessary you can create a custom property The advantage of using one of these properties is that it does no inflict anything on the sheets themselves. Private Sub Workbook_Open() ThisWorkbook.BuiltinDocumentProperties("Comments") = "N" End Sub Sub mySub() If ThisWorkbook.BuiltinDocumentProperties("Comments") = "N" Then do my run once code then set ThisWorkbook.BuiltinDocumentProperties("Comments") = "" End If do my always code End Sub Cheers (and thanks Ardus -- tony ----------------------------------------------------------------------- tony h's Profile: http://www.excelforum.com/member.php...fo&userid=2107 View this thread: http://www.excelforum.com/showthread.php?threadid=54781 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Verify before proceeding
The workbook_open module needs to be ThisWorkbook module (in VB explorer VBAProject...Microsoft Excel Objects... ThisWorkbook) The rest of the code in a standard module. Put some msgbox call in t track what happens eg Private Sub Workbook_Open() ThisWorkbook.BuiltinDocumentProperties("Comments") = "N" MsgBox "initialise" End Sub Sub mySub() If ThisWorkbook.BuiltinDocumentProperties("Comments") = "N" Then MsgBox "run once" ThisWorkbook.BuiltinDocumentProperties("Comments") = "" End If MsgBox "do always" End Sub you should get "initialise" when you open the workbook. The other tw should appear as you run mySu -- tony ----------------------------------------------------------------------- tony h's Profile: http://www.excelforum.com/member.php...fo&userid=2107 View this thread: http://www.excelforum.com/showthread.php?threadid=54781 |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Verify before proceeding
Thanks Tony, works great. -- snowing ------------------------------------------------------------------------ snowing's Profile: http://www.excelforum.com/member.php...o&userid=34576 View this thread: http://www.excelforum.com/showthread...hreadid=547810 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Cannot verify XNPV with PV or HP-12C | Excel Worksheet Functions | |||
Verify email | Excel Discussion (Misc queries) | |||
Several Dates -Verify | Excel Worksheet Functions | |||
Verify names | Excel Programming | |||
Verify Totals | Excel Programming |