Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-13-2017, 12:10 PM
Tech2 Tech2 is offline Command Button Password Windows 7 64bit Command Button Password Office 2010 64bit
Novice
Command Button Password
 
Join Date: Feb 2015
Posts: 3
Tech2 is on a distinguished road
Default Command Button Password

How can I execute this Module when the user clicks the 'Command Button' ?

The Command Button will become active when the user enters the password and follow the link included in the Control.

Private Sub Password()
Answer = InputBox("Enter Password")
If Answer = ("$") Then
ThisDocument.CommandButton12.Enabled = True
Else
ThisDocument.CommandButton12.Enabled = False
End If


End Sub
Private Sub ActiveDocument_Activate()
ThisDocument.CommandButton12.Enabled = False
Password
End Sub

Thanks
Reply With Quote
  #2  
Old 06-13-2017, 11:01 PM
gmayor's Avatar
gmayor gmayor is offline Command Button Password Windows 10 Command Button Password Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Why not to use the button to prompt for the macro and only allow the code associated with the button to run if the password is entered?

Code:
Private Sub CommandButton12_Click()
Const sPassword As String = "password"
Dim sAnswer As String

    sAnswer = InputBox("Enter Password")
    If Not sAnswer = (sPassword) Then
        MsgBox "This function is not available without the correct password."
        GoTo lbl_Exit
    End If
    'Do stuff e.g
    MsgBox "Button code runs"
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 06-20-2017, 07:58 AM
Tech2 Tech2 is offline Command Button Password Windows 7 64bit Command Button Password Office 2010 64bit
Novice
Command Button Password
 
Join Date: Feb 2015
Posts: 3
Tech2 is on a distinguished road
Default

Thanks GM,

When I run the Macro it keeps prompting with the password. It doesn't go to the HyperLink?
Reply With Quote
  #4  
Old 06-20-2017, 08:37 PM
gmayor's Avatar
gmayor gmayor is offline Command Button Password Windows 10 Command Button Password Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

There is no mention of hyperlinks in your post. You asked about password protection. The code I posted just prompts for a password. It doesn't do anything else. You need to replace the lines
Code:
'Do stuff e.g
MsgBox "Button code runs"
with the code that the button is supposed to run.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 06-22-2017, 04:39 AM
Tech2 Tech2 is offline Command Button Password Windows 7 64bit Command Button Password Office 2010 64bit
Novice
Command Button Password
 
Join Date: Feb 2015
Posts: 3
Tech2 is on a distinguished road
Default

Thanks Bud!

It works Great! Sorry about the post. I'll be more specific in the future.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button Password Email from Command Button derajlance Word VBA 6 05-05-2016 07:40 AM
Help with a Command Button dkohnken Word VBA 5 03-18-2015 10:13 PM
command button query smalc Word VBA 2 03-16-2015 08:26 PM
Command Button knp11 PowerPoint 2 01-18-2015 01:41 PM
Command Button Password Command Button cksm4 Word VBA 7 02-27-2011 08:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:17 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft