VBA code to modify a macro

rodonnell

Board Regular
Joined
Jul 9, 2002
Messages
64
I have this macro in a set of workbooks:

Sub print_sch3()
Application.ScreenUpdating = False
With ActiveSheet.PageSetup
.PrintTitleRows = "8:$13"
.PrintTitleColumns = ""
End With
Application.Goto Reference:="Print_sch3_school"

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("schedule3").Select
Range("A8").Select
End Sub

There's an error in this code that I'd like to fix with a macro-there are too many workbooks to update manually. The line that needs to be updated is: .PrintTitleRows = "8:$13". It needs to change to: .PrintTitleRows= "$8:$13".

Can you suggest some code that I should use to make this correction?

Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Why do you need to change that?

If I run the code with either "8:$13" or "$8:$13" the rows to repeat is set to $8:$13 when I check in the Page Layout dialog.
 
Upvote 0
It's a two page print out. The headers rows display correctly on the first page, but not on the second.
 
Upvote 0
If there's too many macros to make this change, could you just add this macro to your PERSONAL.XLSB file and add it to the quick access toolbar? Then it will work in any file you have open and active
 
Upvote 0
if you want VBA to modify VBA you would need something like

Code:
Dim myBook As Workbook
Dim i
Dim j

For Each myBook In Application.Workbooks
For i = 1 To myBook.VBProject.VBComponents.Count
For j = 1 To myBook.VBProject.VBComponents(i).CodeModule.CountOfLines
If myBook.VBProject.VBComponents(i).CodeModule.Lines(j, 1) = ".PrintTitleRows = ""8:$13""" Then
myBook.VBProject.VBComponents(i).CodeModule.DeleteLines j
myBook.VBProject.VBComponents(i).CodeModule.InsertLines j, ".PrintTitleRows = ""$8:$13"""
End If
Next j
Next i
Next myBook
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,643
Members
452,663
Latest member
MEMEH

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