Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Macro vba-Settaggi di Imposta pagina come impostarli da codice?

503 views
Skip to first unread message

PrinsipeMilito

unread,
Apr 22, 2011, 12:50:10 PM4/22/11
to
Salve a tutti,
ho una serie di macro che mi copiano dei valori in un nuovo file excel
(cancellandolo prima e ricreandolo poi) , funziona tutto alla perfezione,
adesso però mi chiedono di riportare anche le impostazioni di pagina
presenti nel foglio originale (quindi : orientamento, proporzioni come ad
esempio imposta al 50%, formato, qualità di stampa, margini, ecc ...)
Il bello è che ogni foglio di lavoro ha le sue impostazioni , quindi quando
vado a creare l'excel nuovo non posso mettergli dei valori di default
(troppo facile sarebbe) , mi chiedevo se c'è un modo di salvare i parametri
tramite macro dall'originale e riportarli successivamente nella copia
grazie mille

Scossa

unread,
Apr 22, 2011, 6:06:49 PM4/22/11
to
On 22 Apr, 18:50, "PrinsipeMilito" <ste.cr...@hotmail.it> wrote:
> Salve a tutti,
> ho una serie di macro che mi copiano dei valori in un nuovo file excel
> (cancellandolo prima e ricreandolo poi) , funziona tutto alla perfezione,
> adesso per mi chiedono di riportare anche le impostazioni di pagina

> presenti nel foglio originale (quindi : orientamento, proporzioni come ad
> esempio imposta al 50%, formato, qualit di stampa, margini, ecc ...)
> Il bello che ogni foglio di lavoro ha le sue impostazioni , quindi quando

> vado a creare l'excel nuovo non posso mettergli dei valori di default
> (troppo facile sarebbe) , mi chiedevo se c' un modo di salvare i parametri

> tramite macro dall'originale e riportarli successivamente nella copia
> grazie mille

Questa sub copia il formato pagina da un worksheet (wsFr) ad un altro
(wsTo):
Puoi fare un ciclo nel quale la chiami per ogni foglio del workbook.

'----------------------
'in un modulo standard:
'
Public Sub setpage(ByVal wsFr As Worksheet, ByVal wsTo As Worksheet)
'by Scossa

Dim xCalc As XlCalculation
Dim bScreen As Boolean
Dim PgSetFr As PageSetup
Dim PgSetTo As PageSetup

With Application
xCalc = .Calculation
bScreen = .ScreenUpdating
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

Set PgSetFr = wsFr.PageSetup
Set PgSetTo = wsTo.PageSetup

With PgSetTo
.BottomMargin = PgSetFr.BottomMargin
.CenterFooter = PgSetFr.CenterFooter
'.CenterFooterPicture = PgSetFr.CenterFooterPicture
.CenterHeader = PgSetFr.CenterHeader
'.CenterHeaderPicture = PgSetFr.CenterHeaderPicture
.CenterHorizontally = PgSetFr.CenterHorizontally
.CenterVertically = PgSetFr.CenterVertically
.FirstPageNumber = PgSetFr.FirstPageNumber
.Zoom = PgSetFr.Zoom
.FitToPagesTall = PgSetFr.FitToPagesTall
.FitToPagesWide = PgSetFr.FitToPagesWide
.FooterMargin = PgSetFr.FooterMargin
.HeaderMargin = PgSetFr.HeaderMargin
.LeftFooter = PgSetFr.LeftFooter
'.LeftFooterPicture = PgSetFr.LeftFooterPicture
.LeftHeader = PgSetFr.LeftHeader
'.LeftHeaderPicture = PgSetFr.LeftHeaderPicture
.LeftMargin = .LeftMargin
.Order = PgSetFr.Order
.Orientation = PgSetFr.Orientation
.PaperSize = PgSetFr.PaperSize
.PrintArea = .PrintArea
.PrintComments = PgSetFr.PrintComments
.PrintGridlines = PgSetFr.PrintGridlines
.PrintHeadings = PgSetFr.PrintHeadings
.PrintQuality = PgSetFr.PrintQuality
.PrintTitleColumns = PgSetFr.PrintTitleColumns
.PrintTitleRows = PgSetFr.PrintTitleRows
.RightFooter = PgSetFr.RightFooter
'.RightFooterPicture = PgSetFr.RightFooterPicture
.RightHeader = PgSetFr.RightHeader
'.RightHeaderPicture = PgSetFr.RightHeaderPicture
.RightMargin = PgSetFr.RightMargin
.TopMargin = PgSetFr.TopMargin
End With


Set wsTo = Nothing
Set wsFr = Nothing
Set PgSetFr = Nothing
Set PgSetTo = Nothing

With Application
.Calculation = xCalc
.ScreenUpdating = bScreen
End With


End Sub
'------------------------

Bye!
Scossa

0 new messages