Checking how a macro is called

E

Ed Davis

I have three macros that are password protected.
Macro 1 is a macro that I run and asks for my password.
Macro 2 is a macro that someone else runs on a daily basis.
Macro 3 is a macro that someone else runs on a daily basis.

I would like to have macro 2 and macro 3 to check if it was called by macro
1 if so, skip asking for a password.

I would run macro 1 sometimes 20 to 30 times at once. so entering the
password each time would be a pain.

I thought something like this:

If called = No then
Ask for the password
rest of code
Else
End sub

I do not know how to determine if it was called or not.
 
D

Don Guillett

One way would be to put a public variable at the top which will empty on
closing file.

public macrocalled

macrocalled=true
 
J

JP Ronse

Hi Ed,

You could try something like this:

Sub M1()
Static M1_PW

If IsEmpty(M1_PW) Then
M1_PW = InputBox(Prompt:="Hello")
End If
M2 M1_PW
End Sub

Sub M2(Optional pasword)
Dim x
If IsMissing(pasword) Then
x = InputBox(Prompt:="Hello")
Else
MsgBox Prompt:="I have already the PW"
End If
End Sub

Macro1 asks once for the password and stores it in M1_PW, it is known as
long as you keep the workbook open.

Macro 1 calls Macro 2 and supplies the password. If it is missing (running
Macro 2 directly) it asks for a password.


Hope this helps.

Wkr,

JP
 
D

David Heaton

I have three macros that are password protected.
Macro 1 is a macro that I run and asks for my password.
Macro 2 is a macro that someone else runs on a daily basis.
Macro 3 is a macro that someone else runs on a daily basis.

I would like to have macro 2 and macro 3 to check if it was called by macro
1 if so, skip asking for a password.

I would run macro 1 sometimes 20 to 30 times at once. so entering the
password each time would be a pain.

I thought something like this:

If called = No then
    Ask for the password
    rest of code
Else
End sub

I do not know how to determine if it was called or not.

Ed,

One other possiblity is this.

In your Macro2 and Macro3 declaration which may look like this

Sub Macro2()

change it to

Sub Macro2(Optional CalledbyM1 as Boolean)

If CalledByM1 then Dont Ask For Password
..
..
..
..
End Sub


When you call Macro 2 and 3 from Macro 1 you just put TRUE in the
variable list

Just an idea

Regards

David
 

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