How change Pagesetup property in the For...Each...Next?

backup69

Active Member
Joined
Jan 20, 2004
Messages
271
Hi all

I have Form with 6 ComboBox:
LeftHeader ; CenterHeader ; RightHeader ; LeftFooter .........

Now i try minimize my code and loop trough the Combobox names and values like this.
Code:
For Each ws In Worksheets
    For Each a In Controls
    If TypeName(a) = "ComboBox" Then
    Select Case a.Value
    Case "Page"

        ws.PageSetup.a.Name = "Page &P"
    
    Case "Page of Pages"

        ws.PageSetup.a.Name = "Page &P of &N"
........
I know (ws.PageSetup.a.Name) this part is wrong. But how i can use ComboBox names for the Pagesetup Header and Footer property?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
after some testing

this works for me
Code:
Dim sh As Worksheet
Dim ctrl As MSForms.Control

Set sh = ActiveSheet
'testline
sh.PageSetup.CenterFooter = "anytext"

    For Each ctrl In Me.Controls
    MsgBox CallByName(sh.PageSetup, ctrl.Name, VbGet)
    Next ctrl
so no problem to "get" it
now searching to "set" it

best regards,
Erik
 
Upvote 0
FOUND IT :-D
Code:
Dim sh As Worksheet
Dim ctrl As Control
Dim txt As String

Set sh = ActiveSheet

    For Each ctrl In Me.Controls
        If TypeName(ctrl) = "ComboBox" Then
        CallByName sh.PageSetup, ctrl.Name, VbLet, ctrl.Value
        End If
    Next ctrl
 
Upvote 0
FINE :-)

I hope you checked the helpfiles to learn something, anyway I did as you can see in the process above :)
 
Upvote 0

Forum statistics

Threads
1,224,386
Messages
6,178,288
Members
452,835
Latest member
ExcelNerd24

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