List Macros - Overwrite on existing worksheet.

Marty Plante

New Member
Joined
Dec 28, 2016
Messages
17
Office Version
  1. 365
Platform
  1. Windows
I have existing code for listing macros in active workbook that creates a new sheet. I want to have it overwrite the existing "List_of_Macros" worksheet. I've created this with codename shtMacroList and the code is in the sheet and is runs on Worksheet_Activate()

I've been unable to find this code where it leaves the original worksheet and overwrites the data with updated list of macros. Any assistance would be appreciated. I do have this working perfectly with a table of contents code.

Sub ListMacros()
Dim VBComp As VBComponent
Dim wsTarget As Worksheet
Dim StartLine As Long
Dim iRow As Integer


Application.ScreenUpdating = False


Set wsTarget = Worksheets.Add
wsTarget.Range("A1") = "Macro"
wsTarget.Range("A1").Font.Bold = True
With wsTarget.Range("A1").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With

iRow = 2

For Each VBComp In ThisWorkbook.VBProject.VBComponents
With VBComp.CodeModule
StartLine = .CountOfDeclarationLines + 1
Do Until StartLine >= .CountOfLines
wsTarget.Cells(iRow, 1) = _
.ProcOfLine(StartLine, vbext_pk_Proc)
iRow = iRow + 1
StartLine = StartLine + _
.ProcCountLines(.ProcOfLine(StartLine, _
vbext_pk_Proc), vbext_pk_Proc)
Loop
End With
Next VBComp

wsTarget.Range("A1").EntireColumn.AutoFit
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Replace this :
VBA Code:
Set wsTarget = Worksheets.Add
wsTarget.Range("A1") = "Macro"
wsTarget.Range("A1").Font.Bold = True
With wsTarget.Range("A1").Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
End With
With this :
VBA Code:
Set wsTarget = Worksheets("List of Macros")
With wsTarget
    Range(.[A2], .Cells(Rows.Count, 1).End(3)).ClearContents
End With
 
Upvote 0
Solution
@Marty Plante - In your future questions, that would be great if you could mark the post that helped to solve the problem in order to help future readers. No need to do anything for this question as I already switched the solution post as confirmed.
 
Upvote 0
@Marty Plante - In your future questions, that would be great if you could mark the post that helped to solve the problem in order to help future readers. No need to do anything for this question as I already switched the solution post as confirmed.
Yes, used the check mark on the right but it did give an error first time. I'll pay extra attention next time around.
 
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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