Solved

VBA apply printing properties in some sheets of the worksheet- not all

Posted on 2012-03-17
8
331 Views
Last Modified: 2012-03-17
I have some sheets, not all the sheets of the workbook that i have to change the header and footer. My code it does well but is very long, I am sure that there is a way to make it more symple, but I don't know how to do it.

My code is:
    Sheets("index").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("PiG").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Detall despeses").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Punt mort").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("BalançC").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("EOAF").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Anàlisi financera").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Anàlisi rendibilitat").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Anàlisi gestió").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Detall Immobilitzat").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Detall Entitats Públiques").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Càlcul Impost S.").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Informació complementaria").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
    Sheets("Resultat-socis").Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With
0
Comment
Question by:joanaplicacions
  • 4
  • 4
8 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 100 total points
Comment Utility
Why not try looping as I was going to suggest in the other question?

Something like this perhaps.
arrShts = Array("index", "PIG", ...., "Resultat-socis") ' fill in rest of sheets where ... is

For I = LBound(arrShts) To UBound(arrShts)

      With Sheets(arrShts(I)).PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "&D"
        .CenterFooter = ""
        .RightFooter = "&P/&N"
    End With

Next I

Open in new window

0
 

Author Closing Comment

by:joanaplicacions
Comment Utility
Thankyou it works ok, I didn't know how to do it
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
I actually expected you to ask in the other question, which is still open.
0
 

Author Comment

by:joanaplicacions
Comment Utility
Help IMnorie, I have already realized that I have test it in a excel that I have already taquen out the headers, now I try to do it again in one that has the logos and it does not work, I do not understand why.

One question, do I have to initialize arrShts value?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:joanaplicacions
Comment Utility
OK
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
Yes you need to declare arrShts like this.
Dim arrShts

Open in new window


How does the code not work?

Does it work for the code you posted but not for some other code?
0
 

Author Comment

by:joanaplicacions
Comment Utility
Hi Imnorie,

I must apologize, it seems that today I am a little bit stupid. I put your code in the wrong position in the new sheet, I have tested again and it works perfectly, sorry.

By the way, I am new in this system, I don't know what I have to do with the other question? How I have to close it?
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
Not sure which one you mean.

You definitely closed one of them, I think you might even have given me some points.

Isn't there a button you can click to close a question and allocate points?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now