Updating many workbooks with macro

akram-5

Board Regular
Joined
Feb 25, 2012
Messages
123
Office Version
  1. 2019
Platform
  1. Windows
Hey Everyone, after a long time I have run into a big problem.
My situation is that I have 63 workbooks that has forms and modules. All of them are project VBA password protected. All of those 63 workbook has similar error that I found out after using for several months. I have considered re doing the workbooks with the correct macro workbook. But I was thinking whether I can use a macro to update them all? I asked chatGPT for help but none of those codes worked. I am getting stuck at the part where I need to use the password to access the project file. Tried different methods it didn’t work. I have the correct password and I m using it to access the files separately.

If anyone could help, I would be grateful. My time is running out and I have to submit all of these financial workbooks today. Please help.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I really don't know you would get around the password entry other than literally sending keystrokes inside of your macro to navigate through the password entry form (see Application.Sendkeys).

Once you're past that, I do have code that does exactly this by programmatically replacing the contents of a target code module with the contents of the module with the fixed code. I can post the whole code that iterates through a list of files if you'd like, but otherwise the relevant parts for updating the code module would look something like:
VBA Code:
''====================================================================================================================================
'' Name:      CopyModuleToTargetWorkbook
'' Desc:      Copies contents of specified module in ThisWorkbook (source) to the specified module in TargetWorkbook (taget).
'' Args:      (a) TargetWorkbook as Workbook ... Workbook to update
''            (b) ModuleName as string ... Name of module to update
'' Returns:   N/A
'' Comments:  (1) https://stackoverflow.com/a/45699086/10802255
''            (2) Must enable 'Microsoft Visual Basic for Applications Extensibility 5.3' reference
''====================================================================================================================================
Private Sub CopyModuleToTargetWorkbook(TargetWorkbook As Workbook, moduleName As String)
    Dim SourceProject As VBIDE.VBProject
    Dim TargetProject As VBIDE.VBProject
    Set SourceProject = ThisWorkbook.VBProject
    Set TargetProject = TargetWorkbook.VBProject
    
    Dim SourceModule As VBIDE.CodeModule
    Dim TargetModule As VBIDE.CodeModule
    Set SourceModule = SourceProject.VBComponents(moduleName).CodeModule
    Set TargetModule = TargetProject.VBComponents(moduleName).CodeModule
    
    With SourceModule
        TargetModule.DeleteLines 1, TargetModule.CountOfLines
        TargetModule.AddFromString .Lines(1, .CountOfLines)
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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