PDA

View Full Version : Active button coding



ukphoenix
07-08-2008, 07:55 PM
Well im back for another lesson on VBA. Ive tried to get this to work from what I've learnt in previous posts but I just keep screwing it up, so I have included the workbook with the buttons added but not active. What I need is some help with the code to get them to do what I want.

The buttons are located on the PFM Tracker sheet with what I need them to do. In addition I'll give you a breakdown of what is required.

Currently when the workbook is opened the user is forced to activate the macros. One of these macros disables the Cut, Copy Paste features within Excel. I need the first button 'Enable Copy' to request a password for activation and once entered the Cut, Copy, Paste feature to be enabled. Then when finished the 2nd button 'Disable Copy' when clicked to re-activate the Cut, Copy, Paste Disabled macro.

Hope that explains it. I have left the PFM Tracker sheet unprotected for who ever wants to play with it. (Not that protection would stop some)

TomSchreiner
07-08-2008, 09:25 PM
Run this little temp sub and then delete it. Replace "password" with the correct password...

Sub TempAddPassword()
ThisWorkbook.Names.Add "PW", "password", False
ThisWorkbook.Save
End Sub

In the worksheet that contains your two buttons.

Private Sub CommandButton1_Click()
If InputBox("Please enter your password...") = [PW] Then
ToggleCutCopyAndPaste True
End If
End Sub

Private Sub CommandButton2_Click()
ToggleCutCopyAndPaste False
End Sub

You should be good to go...

ukphoenix
07-09-2008, 12:11 AM
Thanx Tom works a treat.......

Ive now finished a nightshift and feeling tired but need 1 conditional format added. I have a figure creating in G4 but need a conditional format in J4 that turns red if G4 is >50.
This is probably so easy im gonna hurt my head when I butt the table :banghead: .

General question would be something like

If G4 >50 then J4 turns "red"

TomSchreiner
07-09-2008, 04:45 AM
Select J4
From the Worksheet Menubar
Format, Conditional Formatting
Formula Is
=g4>50
Set your format...