Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 204
Default Can I prevent a user from running a macro?

I have a macro that I want to be able to call from other macros, but it is
important that it cannot be run by users.

I have tried making it Private, but then the other macros also can't call
it.

Is there a way around this?

Thanks

Michelle

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Can I prevent a user from running a macro?


If you place the private module in a separate module and use Option
Private Module it will not show in the Macro list for that workbook.


Code:
--------------------
Option Explicit
Option Private Module

Sub test()
MsgBox "Hello World"
End Sub
--------------------


Place the main code in another module


Code:
--------------------
Option Explicit

Sub main()
test
End Sub
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit 'my web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=35285

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 204
Default Can I prevent a user from running a macro?

Bloomin' marvellous answer - I can't believe I've not come across this
before - Thank you

M

"royUK" wrote in message
...

If you place the private module in a separate module and use Option
Private Module it will not show in the Macro list for that workbook.


Code:
--------------------
Option Explicit
Option Private Module

Sub test()
MsgBox "Hello World"
End Sub
--------------------


Place the main code in another module


Code:
--------------------
Option Explicit

Sub main()
test
End Sub
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit 'my web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=35285


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Can I prevent a user from running a macro?

Another little trick:


If you want all your macros - both the callable and those you want
'invisible' to be in the same Module (which I perfer, if the macros are
handling the same issue), don't use 'Option Private Module', but just make
an optional Dummy on the macros that you want to be invisible.

i.e.:


Public Sub MyMacro()
....code...
End sub


would become:

Public Sub MyMacro(Optional Dummy As Byte)
....code...
End sub

That way you can still call the macro, as you normally would do, but the
macro doesn't show up in the callable macros list.


CE





Michelle wrote:
Bloomin' marvellous answer - I can't believe I've not come across this
before - Thank you

M

"royUK" wrote in message
...

If you place the private module in a separate module and use Option
Private Module it will not show in the Macro list for that workbook.


Code:
--------------------
Option Explicit
Option Private Module

Sub test()
MsgBox "Hello World"
End Sub
--------------------


Place the main code in another module


Code:
--------------------
Option Explicit

Sub main()
test
End Sub
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit 'my web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile:
http://www.thecodecage.com/forumz/member.php?userid=15 View this
thread: http://www.thecodecage.com/forumz/sh...ad.php?t=35285



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Can I prevent a user from running a macro?

You could even ask for a password...

Option Explicit
Sub MichelleOnly()
dim myStr as string

myStr = inputbox(prompt:="What's the password")

if mystr < "ThisISToPSecRet" then
exit sub
end if

'rest of code
End sub

Michelle wrote:

I have a macro that I want to be able to call from other macros, but it is
important that it cannot be run by users.

I have tried making it Private, but then the other macros also can't call
it.

Is there a way around this?

Thanks

Michelle


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
hide/protext auto_open code so user can't prevent it from running Scott Excel Programming 4 May 18th 07 04:40 PM
How do I prevent unintentionally running a Macro? UA_Jeremy Excel Programming 1 September 8th 06 10:51 PM
SHIFT doesn't prevent macro from running at startup Jarryd Excel Programming 3 December 7th 05 09:24 PM
Prevent A Macro From Running If SpreadSheet is Filtered carl Excel Worksheet Functions 1 June 22nd 05 04:04 PM
Prevent running macro upon closing Excel Deneb Excel Programming 2 February 2nd 05 06:07 PM


All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"