S
stuart_bisset
Hi folks
I hope that I am not taking liberties here but the following code which
I have attached to custom dialog box is used so that the user can set
some specific headers and footers on approximately 37 sheets all at
once. The problem is it takes AGES and I'm looking for some advice on
how to quicken up my code. Like I say the only objective is to cycle
through each of these sheets, set the headers & footers to "" then
replace "" with the specified text if the check box on the user form
has been checked. The code is as follows:
*** loads up the user form ***
Sub GoHeader()
frmHeaders.Show
End Sub
*** THIS IS THE OK BUTTON ON THE USER FORM ***
Private Sub CommandButton1_Click()
GetHeaderValues
Unload frmHeaders
HeaderOptions
End Sub
*** THIS GRABS THE USER FORM VALUES ***
Sub GetHeaderValues()
Dim frm As UserForm
Set frm = frmHeaders
gboocb32 = frm.cb32.Value
gboocb33 = frm.cb33.Value
gboocb34 = frm.cb34.Value
End Sub
*** THIS CYCLES THROUGH EACH SHEET ***
Sub HeaderOptions()
Dim frm As UserForm
Dim CurrCell As Range
Dim CurrSheet As String
Dim xloop As Double
Dim yLoop As Double
Dim sht As String
Dim NumUnits As Long
Dim UnitNumber As Long
Dim LoopNumber As Long
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.StatusBar = "Please wait whilst headers and footers are
setup..."
LoopNumber = Application.Names("sysListWorkSheets").RefersToRange.Count
NumUnits = Application.Names("sysUnitList").RefersToRange.Count - 2
''' records the cell currently selected by the user
CurrSheet = ActiveSheet.Name
Set CurrCell = Application.Selection
''' loops thru all sheets and sets headers & footers to nothing
''' then resets them to the correct values
'main sheets
For xloop = 1 To LoopNumber
sht = Range("sysListWorksheets").Item(xloop).Value
HeadersAndFooters (sht)
Next xloop
'business unit sheets
For xloop = 1 To NumUnits
UnitNumber = Range("sysunitnumbers").Item(xloop + 1)
For yLoop = 1 To 4
sht = "Unit " & UnitNumber & " " &
Range("sysListUnitSheets").Item(yLoop)
HeadersAndFooters (sht)
Next yLoop
Next xloop
Worksheets(CurrSheet).Activate
Range(CurrCell.Address).Select
CalculationSetUp
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub
*** SETS THE HEADER AND FOOTER ***
Sub HeadersAndFooters(sht As String)
With Worksheets(sht).PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
If gboocb33 = True Then
.LeftHeader = "&""Arial,Bold""& Private and Confidential"
End If
If gboocb34 = True Then
.RightHeader = "&""Arial,Bold""& DRAFT - for discussion
purposes only"
End If
If gboocb34 = True Then
.LeftFooter = "&""Arial,Regular""& Prepared by Company
Name"
End If
End With
End Sub
***********************************
I would be very grateful for any comments & insights that you have for
me.
Cheers & TIA
Stuart
I hope that I am not taking liberties here but the following code which
I have attached to custom dialog box is used so that the user can set
some specific headers and footers on approximately 37 sheets all at
once. The problem is it takes AGES and I'm looking for some advice on
how to quicken up my code. Like I say the only objective is to cycle
through each of these sheets, set the headers & footers to "" then
replace "" with the specified text if the check box on the user form
has been checked. The code is as follows:
*** loads up the user form ***
Sub GoHeader()
frmHeaders.Show
End Sub
*** THIS IS THE OK BUTTON ON THE USER FORM ***
Private Sub CommandButton1_Click()
GetHeaderValues
Unload frmHeaders
HeaderOptions
End Sub
*** THIS GRABS THE USER FORM VALUES ***
Sub GetHeaderValues()
Dim frm As UserForm
Set frm = frmHeaders
gboocb32 = frm.cb32.Value
gboocb33 = frm.cb33.Value
gboocb34 = frm.cb34.Value
End Sub
*** THIS CYCLES THROUGH EACH SHEET ***
Sub HeaderOptions()
Dim frm As UserForm
Dim CurrCell As Range
Dim CurrSheet As String
Dim xloop As Double
Dim yLoop As Double
Dim sht As String
Dim NumUnits As Long
Dim UnitNumber As Long
Dim LoopNumber As Long
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.StatusBar = "Please wait whilst headers and footers are
setup..."
LoopNumber = Application.Names("sysListWorkSheets").RefersToRange.Count
NumUnits = Application.Names("sysUnitList").RefersToRange.Count - 2
''' records the cell currently selected by the user
CurrSheet = ActiveSheet.Name
Set CurrCell = Application.Selection
''' loops thru all sheets and sets headers & footers to nothing
''' then resets them to the correct values
'main sheets
For xloop = 1 To LoopNumber
sht = Range("sysListWorksheets").Item(xloop).Value
HeadersAndFooters (sht)
Next xloop
'business unit sheets
For xloop = 1 To NumUnits
UnitNumber = Range("sysunitnumbers").Item(xloop + 1)
For yLoop = 1 To 4
sht = "Unit " & UnitNumber & " " &
Range("sysListUnitSheets").Item(yLoop)
HeadersAndFooters (sht)
Next yLoop
Next xloop
Worksheets(CurrSheet).Activate
Range(CurrCell.Address).Select
CalculationSetUp
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub
*** SETS THE HEADER AND FOOTER ***
Sub HeadersAndFooters(sht As String)
With Worksheets(sht).PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
If gboocb33 = True Then
.LeftHeader = "&""Arial,Bold""& Private and Confidential"
End If
If gboocb34 = True Then
.RightHeader = "&""Arial,Bold""& DRAFT - for discussion
purposes only"
End If
If gboocb34 = True Then
.LeftFooter = "&""Arial,Regular""& Prepared by Company
Name"
End If
End With
End Sub
***********************************
I would be very grateful for any comments & insights that you have for
me.
Cheers & TIA
Stuart