LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default modify a macro with a macro

I'm working on a program to change the passwords in some of the
worksheets in the workbook. I've got it, with some help, to change the
worksheet passwords. Now I need it to go into 2 existing macros that
extract data from the password protected worksheets and change the
passwords there. This code is in a userform that is called for the user
to input the 2 existing passwords and the 2 new ones, which are entered
twice each for verification.
I've never tried to edit a macro from a macro. Here is the code so far:

Private Sub cbOK_Click()
Dim sOldMnthlyShtPWORD As String
Dim sOldTtlShtPWORD As String
Dim sNewTtlShtPWORD1 As String
Dim sNewTtlShtPWORD2 As String
Dim sNewMnthlyShtPWORD1 As String
Dim sNewMnthlyShtPWORD2 As String
Dim ws As Worksheet

sOldMnthlyShtPWORD = ufPswrdChange.tboxOldMnthlyShtPword.Value
sOldTtlShtPWORD = ufPswrdChange.tboxOldTtlShtPword.Value
sNewTtlShtPWORD1 = ufPswrdChange.tboxNewTtlShtPword1.Value
sNewTtlShtPWORD2 = ufPswrdChange.tboxNewTtlShtPword2.Value
sNewMnthlyShtPWORD1 = ufPswrdChange.tboxNewMnthlyShtPword1.Value
sNewMnthlyShtPWORD2 = ufPswrdChange.tboxNewMnthlyShtPword2.Value

ufPswrdChange.Hide


If Len(sOldMnthlyShtPWORD) = 0 Then
MsgBox "The old Totals sheet password is blank. Please enter the
password.", vbOKOnly
Call PasswordChange
End If

If Len(sOldTtlShtPWORD) = 0 Then
MsgBox "The old Monthly sheet password is blank. Please enter the
password.", vbOKOnly
Call PasswordChange
End If

If Len(sNewTtlShtPWORD1) = 0 Then
MsgBox "The first new Title sheet password is blank. Please enter
the password.", vbOKOnly
Call PasswordChange
End If

If Len(sNewTtlShtPWORD2) = 0 Then
MsgBox "The second new Title sheet password is blank. Please enter
the password.", vbOKOnly
Call PasswordChange
End If

If Len(sNewMnthlyShtPWORD1) = 0 Then
MsgBox "The first new Monthly sheet password is blank. Please enter
the password.", vbOKOnly
Call PasswordChange
End If

If Len(sNewMnthlyShtPWORD2) = 0 Then
MsgBox "The second new Monthly sheet password is blank. Please enter
the password.", vbOKOnly
Call PasswordChange
End If


'If sNewTtlShtPword1 < sNewTtlShtPword2 Then
' MsgBox "The new Title sheet passwords don't match. Please re-enter
them", vbOKOnly
' Call PasswordChange
'
'End If
If sNewMnthlyShtPWORD1 < sNewMnthlyShtPWORD2 Then
MsgBox "The new Monthly sheet passwords don't match. Please re-enter
them", vbOKOnly
Call PasswordChange
End If

For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "*Monthly" Then
ws.Unprotect Password:=sOldMnthlyShtPWORD
ws.Protect Password:=sNewMnthlyShtPWORD1
End If
If ws.Name = "TOTALS" Then
ws.Unprotect Password:=sOldTtlShtPWORD
ws.Protect Password:=sNewTtlShtPWORD1
End If
Next

End Sub

If I want this code to also modify a module in the same spreadsheet
named "ModCount" and change the password there. If someone can get me
pointed in the right direction, I'd appreciate it.

 
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
I need to modify my macro ... Dr. Darrell Excel Discussion (Misc queries) 0 February 24th 10 07:21 PM
Modify A Macro carl Excel Worksheet Functions 1 September 27th 07 08:39 PM
Modify a Macro Carl Excel Worksheet Functions 1 October 28th 06 10:32 AM
Modify a macro Philippe Jacquet Excel Programming 0 January 4th 06 08:45 AM
Help to modify macro please Brian Tozer Excel Programming 2 December 28th 03 08:24 PM


All times are GMT +1. The time now is 02:50 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"