modificare l'area di stampa di tutti i fogli di una cartella di lavoro

67 views
Skip to first unread message

Fabio Fable

unread,
Feb 5, 2013, 4:54:17 AM2/5/13
to excel_v...@googlegroups.com
Ciao a tutti. Ho bisogno del vostro aiuto , dato che le mie routine VBA sono peggio delle cimici dentro i primi computer a valvole ;(
Vorrei impostare l'area di stampa in tutti i fogli di lavoro di una cartella Excel (Excel 2007). 
Ho scritto questo:

Option Explicit
Dim ws As Worksheet

Sub SetAttributes()
      For Each ws In ActiveWorkbook.Worksheets
      
            Worksheets("Abano").PageSetup.PrintArea = "$A$1:$L$51"
      Next ws
   End Sub

   ' The workbook containing the following macro also includes a
   ' worksheet called Sheet1, which is the source of the PageSetup
   ' information that you want to use to format the worksheets in
   ' another workbook.

   ' Before you run this macro, make sure that the second workbook
   ' is active.

   Sub SetWorkbookAttributes()
      For Each ws In ActiveWorkbook.Worksheets
         ws.PageSetup.PrintArea = _
            ThisWorkbook.Worksheets("Abano").PageSetup.PrintArea
      Next ws
   End Sub

purtroppo però la routine mi dà errore.
In pratica imposto nel primo foglio un'area di stampa e poi a partire dal secondo foglio lui dovrebbe impostare l'area di stampa come per quella del foglio "Abano". Ottengo però un errore.
Qualcuno mi saprebbe aiutare ?
Grazie come sempre per il vostro aiuto !!


roberto mensa

unread,
Feb 5, 2013, 5:17:59 AM2/5/13
to excel_v...@googlegroups.com
questa:
   Sub SetWorkbookAttributes()
      For Each ws In ActiveWorkbook.Worksheets
         ws.PageSetup.PrintArea = _
            ThisWorkbook.Worksheets("Abano").PageSetup.PrintArea
      Next ws
   End Sub
 
ha un solo problema, non è coerente visto che activeworkbook e thisworkbook sono 2 proprietà che restituiscono non sempre lo stesso oggetto ...
 
quindi pui modificare così:
 
   Sub SetWorkbookAttributes()
      For Each ws In ThisWorkbook.Worksheets

         ws.PageSetup.PrintArea = _
            ThisWorkbook.Worksheets("Abano").PageSetup.PrintArea
      Next ws
   End Sub
oppure:
 Sub SetWorkbookAttributes()
      For Each ws In ActiveWorkbook.Worksheets
         ws.PageSetup.PrintArea = _
            ActiveWorkbook.Worksheets("Abano").PageSetup.PrintArea
      Next ws
   End Sub
 
e prima di scegliere ... leggi la guida a proposito di  activeworkbook e thisworkbook
saluti
r
 
 
--
--
Hai ricevuto questo messaggio in quanto sei iscritto al gruppo "Excel VBA" di Google Gruppi.
Per mandare un messaggio a questo gruppo, invia una email a
excel_v...@googlegroups.com
Per modificare la tua iscrizione
http://groups.google.it/group/excel_vba_free/subscribe?hl=it
Per maggiori opzioni, visita questo gruppo all'indirizzo
http://groups.google.it/group/excel_vba_free?hl=it?hl=it
 
---
Hai ricevuto questo messaggio perché sei iscritto al gruppo "Excel VBA" di Google Gruppi.
Per annullare l'iscrizione a questo gruppo e non ricevere più i suoi messaggi, invia un'email a excel_vba_fre...@googlegroups.com.
Per ulteriori opzioni, visita https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages