Macro Updated by Macro ?

ayazgreat

Well-known Member
Joined
Jan 19, 2008
Messages
1,151
Hi All

How should I update a macro by a macro ? meaning to say that codes are replaced by new codes in module.

Suppose I have workbook named Ayaz.xls containing module named "TDP" which is protectd by VBA Password(Lock Project). I want codes to be updated/replaced by New codes.

For example I have following codes

Code:
Private Sub CopySheet1()
   
    With Sheet1.UsedRange
        Sheet2.Range("A1").Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
End Sub

want change to

Code:
 [/COLOR]
[COLOR=black]Private Sub CopySheet1()
   
    With Sheet1.UsedRange
        [COLOR=red]Sheet3.[/COLOR]Range[COLOR=red]("[/COLOR][COLOR=red]C2").[/COLOR]Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
End Sub[/COLOR]
[COLOR=black]

Thanks in advance
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Greetings ayazgreat,

The link John supplied has both how to programatically create a procedure as well how to delete a procedure.

...Suppose I have workbook named Ayaz.xls containing module named "TDP" which is protectd by VBA Password(Lock Project)....

However, I do not believe anyone here is going to discuss how to programatically thwart password protection.

Mark
 
Upvote 0
And GTO where do you stand about mentioned below coeds where is an error message after running ?

Code:
Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)
  
'Function to unlock VBA Project if password is known
  
Dim VBP As VBProject, oWin As VBIDE.Window
  
Dim wbActive As Workbook
  
Dim i As Integer
  
Set VBP = WB.VBProject
  
Set wbActive = ActiveWorkbook
  
If VBP.Protection <> vbext_pp_locked Then Exit Sub
  
Application.ScreenUpdating = True
  
'Close any code windows to ensure we hit the right project
  
For Each oWin In VBP.VBE.Windows
  
If InStr(oWin.Caption, "(") > 0 Then oWin.Close
  
Next oWin
  
WB.Activate
  
' Now use lovely SendKeys to unprotect
  
Application.OnKey "%{F11}"
  
SendKeys "%{F11}%TE" & Password & "~~%{F11}", True
  
'Check to see if project unlocked
  
If VBP.Protection = vbext_pp_locked Then
  
' if failed - maybe wrong password
  
SendKeys "%{F11}%TE", True
  
End If
  
' Leave no evidence of the password
  
Password = ""
  
' Go back to the previously active workbook
  
wbActive.Activate
  
End Sub
  
Sub UnprotectProjectandImportVBAmodule()
  
'Use function to unprotect VBA Project
  
UnprotectVBProject Workbooks("Target.xls"), "password"
  
'Import required VBA Module to target workbook
  
Workbooks("Target.xls").VBProject.VBComponents.Import file
  
'Filename:="X:\Development\STP.bas"
  
'Activate target workbook
  
Workbooks("Target.xls").Activate
  
'Run macro residing in target workbook
  
'Run "Target.xls!testone"
  
End Sub
  
'CODE IN Target.xls
  
Sub testone()
  
'MsgBox ("You have unlocked the project, imported the module called
'STP.bas, and run the intended macro")
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top