Discussione:
Macro stampa
(troppo vecchio per rispondere)
Giuseppe
2006-08-04 06:33:02 UTC
Permalink
Buongiorno.
Mauro Gamberini mi ha suggerito questa macro per selzionare i Fogli da
stampare e avere una maschera di selezione stampate e impostazioni di stampa
prima di stampare.
L'ho provato ma non funziona bene in quanto la maschera non mi si chiude sia
nel caso clicchi su OK che su Annulla.
Qualcuno può aiutarmi? Grazie
Giuseppe
Public Sub mStampa()
Dim wsh As Worksheet
'Application.Dialogs(xlDialogPrint).Show '<--Scelta stampante
'Application.Dialogs (xlDialogPrintPreview) '<--Anteprima
For Each wsh In Worksheets
Application.Dialogs(xlDialogPrinterSetup).Show
Select Case wsh.Name
Case Is = "Foglio1", "Foglio2"
wsh.PrintOut
End Select
Next
End Sub
--
Giuseppe
Norman Jones
2006-08-04 06:58:22 UTC
Permalink
Ciao Giuseppe,
Post by Giuseppe
Mauro Gamberini mi ha suggerito questa macro per selzionare i Fogli da
stampare e avere una maschera di selezione stampate e impostazioni di stampa
prima di stampare.
L'ho provato ma non funziona bene in quanto la maschera non mi si chiude sia
nel caso clicchi su OK che su Annulla.
Qualcuno può aiutarmi? Grazie
In risposta alla tua domanda originale, avevo suggerito:

http://www.j-walk.com/ss/excel/tips/tip48.htm


Hai provato?


---
Regards,
Norman
Giuseppe
2006-08-04 09:18:03 UTC
Permalink
Si, l'avevo già visto. Grazie
Le due macro che però mi avevo mandato Mauro Gamberini mi sono sembrate più
alla mia portata e pienamente rispondenti alle mie esigenze. La prima (quella
di ulteriore consenso alla stampa) funziona perfettamente, l'altra quella che
mi da la possibilità di scegliere la stampante e le impostazioni di stampa
non mi funziona bene.
Ancora grazie.
--
Giuseppe
Post by Norman Jones
Ciao Giuseppe,
Post by Giuseppe
Mauro Gamberini mi ha suggerito questa macro per selzionare i Fogli da
stampare e avere una maschera di selezione stampate e impostazioni di stampa
prima di stampare.
L'ho provato ma non funziona bene in quanto la maschera non mi si chiude sia
nel caso clicchi su OK che su Annulla.
Qualcuno può aiutarmi? Grazie
http://www.j-walk.com/ss/excel/tips/tip48.htm
Hai provato?
---
Regards,
Norman
Franz Verga
2006-08-05 01:52:25 UTC
Permalink
Post by Norman Jones
Ciao Giuseppe,
Post by Giuseppe
Mauro Gamberini mi ha suggerito questa macro per selzionare i Fogli
da stampare e avere una maschera di selezione stampate e
impostazioni di stampa
prima di stampare.
L'ho provato ma non funziona bene in quanto la maschera non mi si chiude sia
nel caso clicchi su OK che su Annulla.
Qualcuno può aiutarmi? Grazie
http://www.j-walk.com/ss/excel/tips/tip48.htm
Ciao Norman,
dal tuo link sono arrivato a quest'altro link:

http://www.j-walk.com/ss/excel/tips/tip76.htm

il quale sfrutta una funzione per creare a un modulo al volo e fare le
stesse cose...
Ho provato ad utilizzare il file d'esempio fornito da J.W., ma mi da errore
di run-time 1004: Metodo VBE dell'oggetto Application non riuscito,
evidenziando la seguente riga:

Application.VBE.MainWindow.Visible = False

perché questo comportamento strano? Eppure dovrebbe funzionare...
--
Ciao

Franz Verga
Norman Jones
2006-08-05 08:14:16 UTC
Permalink
Ciao Franz,

Innanzitutto, la riga problematica non e' necessaria; io utilizzo un mio
codice analogo il quale non include quest'istruzione.

Stai usando quale versione di Excel? Se fosse xl2003, dal VBA Help:

'-----------------------------------
A method or property can't be used because of security settings. For
example, the properties and methods of the VBE object for manipulating
the Microsoft Visual Basic for Applications (VBA) code stored in an
Microsoft Office document are inaccessible by default.
To turn on trusted access to Visual Basic Projects:

On the Tools menu, point to Macro, and then click Security.
On the Trusted Sources tab, select the Trust access to Visual Basic
Project check box.
'-----------------------------------

Comunque, per gli scopi di Giuseppe, preferirei il dialogo (Tip 48) <g>


---
Regards,
Norman
Franz Verga
2006-08-05 10:34:32 UTC
Permalink
Post by Norman Jones
Ciao Franz,
Innanzitutto, la riga problematica non e' necessaria; io utilizzo un
mio codice analogo il quale non include quest'istruzione.
Avevo pure provato a commentare (=a renderla commento, mediante
l'anteposizione di un apice " ' ") la riga, ma in questo caso si bloccava su
quest'altra:

Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3)

che, invece, mi pare abbastanza fondamentale... :-)
Sì, ho Excel 2003 ed il tuo suggerimento è stato prezioso.
Post by Norman Jones
Comunque, per gli scopi di Giuseppe, preferirei il dialogo (Tip 48)
Sì, è indubbiamente più funzionale, anche perché permette di selezionare più
opzioni contemporaneamente, mentre con la funzione GetOption (tip 76) se ne
può selezionare una per volta...
--
Ciao

Franz Verga
Giuseppe
2006-08-05 16:50:02 UTC
Permalink
Ciao Norman.
Ho provato la macro da te suggerita (Tip 48). Funziina bene ed è veramente
utile. Grazie. Ho applicato anche la modifica che veniva suggerita nel sito
da te indicato che permette di stampare con una numerazione progressiva
automativìca i vari fogli selezionati. E questa è una cosa ancora più utile.
Infatti mi chiedevo da tempo come si potesse stampare i fogli in sequenza
senza ogni volta andare a impostare la numerazione manuale!! Doppio grazie.
A questo punto però mi serve un altro piccolo aiuto:
Poiché io uso delle cartelle con molti fogli ma solo alcuni da stampare e
sono sempre gli stessi come posso impostarli indicandogli già nella scrittura
della macro (come suggeriva Mauro Gamberini)? Inoltre come posso fare in modo
che prima di stampare mi venga richiesto di selezionare la stampante?

Riporto la macro che sto usando con la preghiera di indicarmi le modifiche:

Option Explicit
Sub SelectSheets()
Dim i As Integer
Dim TopPos As Integer
Dim SheetCount As Integer
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox
Application.ScreenUpdating = False

' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If

' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add

SheetCount = 0

' Add the checkboxes
TopPos = 40
For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) <> 0 And _
CurrentSheet.Visible Then
SheetCount = SheetCount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(SheetCount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i

' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240

' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Seleziona Fogli da stampare"
End With

' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront

' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If SheetCount <> 0 Then
If PrintDlg.Show Then
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Select Replace:=False
End If
Next cb
ActiveWindow.SelectedSheets.PrintOut copies:=1
ActiveSheet.Select
End If

Else
MsgBox "All worksheets are empty."
End If

' Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
PrintDlg.Delete

' Reactivate original sheet
CurrentSheet.Activate
End Sub


GRAZIE ANCORA.

Giuseppe
Post by Norman Jones
Comunque, per gli scopi di Giuseppe, preferirei il dialogo (Tip 48) <g>
---
Regards,
Norman
Norman Jones
2006-08-05 17:57:52 UTC
Permalink
Ciao Giuseppe,

'--------------------
Poiché io uso delle cartelle con molti fogli ma solo alcuni da
stampare e sono sempre gli stessi come posso impostarli
indicandogli già nella scrittura della macro (come suggeriva
Mauro Gamberini)? Inoltre come posso fare in modo che
prima di stampare mi venga richiesto di selezionare la stampante?
'--------------------

Allora, invece del codice di John Walkenbach, prova:

'=============>>
Public Sub PrintMySheets()
Dim WB As Workbook
Dim SH As Worksheet
Dim arrSheets As Variant

Set WB = ActiveWorkbook

arrSheets = Array("Foglio1", "Foglio3", _
"Foglio5", "Fogio99") '<<=== da CAMBIARE

For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = "PAGE &P of &N"
End With
Next SH

Application.Dialogs(xlDialogPrinterSetup).Show
Sheets(arrSheets).PrintOut copies:=1

For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = ""
End With
Next SH

End Sub
'<<=============

Per utilizzare questo codice con qualsiasi file attivo, prova ad
assegnare la suddetta macro ad un pulsante inserito in una
barra degli strumenti.


---
Regards,
Norman
Norman Jones
2006-08-05 18:20:12 UTC
Permalink
Ciao Giussepe,
Post by Norman Jones
Per utilizzare questo codice con qualsiasi file attivo, prova ad
assegnare la suddetta macro ad un pulsante inserito in una
barra degli strumenti.
E se volessi fare così, dovessi incollare il codice in un modulo standard
sia nel tuo Personal.xls che in un componente aggiuntivo.


---
Regards,
Norman
Norman Jones
2006-08-05 22:05:31 UTC
Permalink
Ciao Giuseppe,

Meglio sarebbe la seguente versione:

'=============>>
Public Sub PrintMySheets()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range
Dim arrSheets As Variant

Set WB = ActiveWorkbook
Set rng = Selection
Set rCell = ActiveCell

arrSheets = Array("Foglio1", "Foglio3", _
"Foglio5", "Fogio99") '<<=== da CAMBIARE

For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = "PAGE &P of &N"
End With
Next SH

Application.Dialogs(xlDialogPrinterSetup).Show
Sheets(arrSheets).PrintOut copies:=1

For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = ""
End With
Next SH

ActiveSheet.Select
Application.Goto rng
rCell.Activate

End Sub
'<<=============


---
Regards,
Norman
Giuseppe
2006-08-06 06:49:01 UTC
Permalink
Grazie Norman.
Funziona davvero a meraviglia. Adesso posso usare il codice "Norman Jones"
in cartelle con sempre gli stessi fogli da stampare, oppure il codice "John
Walkenbach" in cartelle con fogli da stampare che possono variare di volta in
volta.
Ancora molte grazie e tanti complimenti per la tua bravura.
--
Giuseppe
Post by Norman Jones
Ciao Giuseppe,
'=============>>
Public Sub PrintMySheets()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range
Dim arrSheets As Variant
Set WB = ActiveWorkbook
Set rng = Selection
Set rCell = ActiveCell
arrSheets = Array("Foglio1", "Foglio3", _
"Foglio5", "Fogio99") '<<=== da CAMBIARE
For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = "PAGE &P of &N"
End With
Next SH
Application.Dialogs(xlDialogPrinterSetup).Show
Sheets(arrSheets).PrintOut copies:=1
For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = ""
End With
Next SH
ActiveSheet.Select
Application.Goto rng
rCell.Activate
End Sub
'<<=============
---
Regards,
Norman
Giuseppe
2006-08-06 07:09:01 UTC
Permalink
Scusa Norman. Ancora un'ultima cosa.
E se volessi combinare le due Macro? Cioè se volessi avere la macro di "John
Walkenbach" che permette di selezionare i fogli attivi da stampare combinata
con la parte della tua macro che mi permette di scegliere la stampante. Quale
sarebbe in questo caso il codice?
Ciao grazie
--
Giuseppe
Post by Giuseppe
Grazie Norman.
Funziona davvero a meraviglia. Adesso posso usare il codice "Norman Jones"
in cartelle con sempre gli stessi fogli da stampare, oppure il codice "John
Walkenbach" in cartelle con fogli da stampare che possono variare di volta in
volta.
Ancora molte grazie e tanti complimenti per la tua bravura.
--
Giuseppe
Post by Norman Jones
Ciao Giuseppe,
'=============>>
Public Sub PrintMySheets()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range
Dim arrSheets As Variant
Set WB = ActiveWorkbook
Set rng = Selection
Set rCell = ActiveCell
arrSheets = Array("Foglio1", "Foglio3", _
"Foglio5", "Fogio99") '<<=== da CAMBIARE
For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = "PAGE &P of &N"
End With
Next SH
Application.Dialogs(xlDialogPrinterSetup).Show
Sheets(arrSheets).PrintOut copies:=1
For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = ""
End With
Next SH
ActiveSheet.Select
Application.Goto rng
rCell.Activate
End Sub
'<<=============
---
Regards,
Norman
Norman Jones
2006-08-06 11:13:47 UTC
Permalink
Ciao Giuseppe,

'-------------------
Scusa Norman. Ancora un'ultima cosa.
E se volessi combinare le due Macro? Cioè se volessi avere la macro
di "John Walkenbach" che permette di selezionare i fogli attivi da
stampare combinata con la parte della tua macro che mi permette di
scegliere la stampante. Quale sarebbe in questo caso il codice
'-------------------

Allora, Giuseppe, suggerirei due soluzioni alternative.

Nella prima soluzione, aggiungo una terza macro assegnata ad un pulsante
nella barra degli strumenti. Secondo la risposta dell'utente, sia la macro
di John Walkenbach che la macro di Norman sarà eseguita:

'=============>>
Public Sub NormanOrJohn()
Dim Res As VbMsgBoxResult

Res = MsgBox(Prompt:="Vuoi SCEGLIERE i fogli da stampare?" _
& vbNewLine & vbNewLine _
& "Se rispondi di no, i fogli " _
& "predeterminati saranno stampati", _
Buttons:=vbYesNo, _
Title:="STAMPARE")
If Res = vbYes Then
Call SelectSheets
Else
Call PrintMySheets
End If
End Sub

'---------------->>

Public Sub SelectSheets()
'John Walkenbach / Aaron Blood
Dim i As Long
Dim TopPos As Long
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox
Dim Sheetcount As Long '<<=== NUOVA dichiarazione!

Application.ScreenUpdating = False

' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If

' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add

Sheetcount = 0

' Add the checkboxes
TopPos = 40
For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) <> 0 And _
CurrentSheet.Visible Then
Sheetcount = Sheetcount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(Sheetcount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i

' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240

' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Seleziona Fogli da stampare"
End With

' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront

' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If Sheetcount <> 0 Then
If PrintDlg.Show Then
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Select Replace:=False
End If
Next cb
ActiveWindow.SelectedSheets.PrintPreview 'Out copies:=1
ActiveSheet.Select
End If

Else
MsgBox "All worksheets are empty."
End If

' Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
PrintDlg.Delete

' Reactivate original sheet
CurrentSheet.Activate
End Sub

'---------------->>

Public Sub PrintMySheets()
'Norman Jones
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range
Dim arrSheets As Variant

Set WB = ActiveWorkbook
Set rng = Selection
Set rCell = ActiveCell

arrSheets = Array("Foglio1", "Foglio3", _
"Foglio5"', "Fogio99") '<<=== da CAMBIARE

For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = "Pagina &P of &N" '<<=== CAMBIATA
End With
Next SH

Application.Dialogs(xlDialogPrinterSetup).Show
Sheets(arrSheets).PrintOut copies:=1

For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = ""
End With
Next SH

ActiveSheet.Select
Application.Goto rng
rCell.Activate

End Sub
'<<=============


Per la seconda soluzione, ho adattato la macro di John Walkenbach per:

- permettere la selezione della stampante
- permettere la numerazione successiva delle pagine stampate
- permettere la selezione di un gruppo predeterminato dei fogli

'=============>>
Public Sub SelectSheets2()
'John Walkenbach / Norman Jones
Dim i As Long
Dim TopPos As Long
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox
Dim Sheetcount As Long '<<== Nuova dichiarazione!
Dim PreSelezionati As CheckBox '<<=== Nuova variabile
Dim arrSheets As Variant '<<=== Nuova variabile
Dim SH As Worksheet '<<=== Nuova variabile

Application.ScreenUpdating = False

'Nuova Riga
arrSheets = Array("Foglio1", "Foglio3", _
"Foglio5"', "Fogio99") '<<== da cambiare

' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If

' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add

Sheetcount = 0

' Add the checkboxes
TopPos = 40

For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) <> 0 And _
CurrentSheet.Visible Then
Sheetcount = Sheetcount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(Sheetcount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i

'Creare un nuovo controllo per velocemente '<<== Nuova Riga
' selezionare i fogli predeterminati
Set PreSelezionati = PrintDlg.CheckBoxes. _
Add(78, TopPos, 150, 16.5) '<<== Nuova Riga
PreSelezionati.Text = "PreScelti" '<<== Nuova Riga
TopPos = TopPos + 13 '<<== Nuova Riga

' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240

' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Seleziona Fogli da stampare"
End With

' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront

' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If Sheetcount <> 0 Then
If PrintDlg.Show Then
If PreSelezionati.Value = xlOn Then
Sheets(arrSheets).Select '<<== Nuova Riga
Else '<<==
Nuova Riga
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Select Replace:=False
End If
Next cb
End If '<<== Nuova
Riga

For Each SH In ActiveWindow. _
SelectedSheets '<<== Nuova Riga
With SH.PageSetup '<<== Nuova Riga
.CenterHeader = _
"Pagina &P of &N" '<<== Nuova Riga
End With '<<== Nuova
Riga
Next SH '<<== Nuova
Riga

Application.Dialogs(xlDialogPrinterSetup).Show

ActiveWindow.SelectedSheets.PrintOut copies:=1

For Each SH In ActiveWindow. _
SelectedSheets '<<== Nuova Riga
With SH.PageSetup '<<== Nuova Riga
.CenterHeader = "" '<<== Nuova Riga
End With '<<== Nuova
Riga
Next SH '<<== Nuova
Riga
ActiveSheet.Select
End If
Else
MsgBox "All worksheets are empty."
End If

' Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
PrintDlg.Delete

' Reactivate original sheet
CurrentSheet.Activate

End Sub
'<<=============


---
Regards,
Norman
Norman Jones
2006-08-06 11:36:08 UTC
Permalink
Ciao Giuseppe,
Post by Norman Jones
Else '<<==
Nuova Riga
il codice dovrebbe essere letto come un singola riga, i.e.:

Else '<<== Nuova Riga

[La doppia riga e' il lavoro di OE ... :-((]



---
Regards,
Norman
Giuseppe
2006-08-06 16:34:01 UTC
Permalink
Ciao Norman. Grazie per tutte le informazioni. Anche se tante informazioni
per me che non sono esperto mi mettono facilmente in confusione.

1° Problema. Questa tua Macro mi va benissimo ma........La finestra di
dialogo "seleziona stampante" non funzione bene perché se clicco su "Annulla"
la stampa non viene annullata ma viene lanciata.

Public Sub PrintMySheets()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range
Dim arrSheets As Variant

Set WB = ActiveWorkbook
Set rng = Selection
Set rCell = ActiveCell

arrSheets = Array("Foglio1", "Foglio3") '<<=== da CAMBIARE

For Each SH In Sheets(arrSheets)
With SH.PageSetup

End With
Next SH

Application.Dialogs(xlDialogPrinterSetup).Show
Sheets(arrSheets).PrintOut copies:=1

For Each SH In Sheets(arrSheets)
With SH.PageSetup
.CenterHeader = ""
End With
Next SH

ActiveSheet.Select
Application.Goto rng
rCell.Activate

End Sub


2° Problema.
Vorrei semplicemnte un'altra macro che mi permetta come questa che ti ho
riportato oltre che di scegliere la stampante di selezionare i Fogli da
stampare così come consente la Macro di John Walkenbach


Option Explicit
Sub SelectSheets()
Dim i As Integer
Dim TopPos As Integer
Dim SheetCount As Integer
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox
Application.ScreenUpdating = False

' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If

' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add

SheetCount = 0

' Add the checkboxes
TopPos = 40
For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) <> 0 And _
CurrentSheet.Visible Then
SheetCount = SheetCount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(SheetCount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i

' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240

' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Seleziona Fogli da stampare"
End With

' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront

' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If SheetCount <> 0 Then
If PrintDlg.Show Then
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Select Replace:=False
End If
Next cb
ActiveWindow.SelectedSheets.PrintOut copies:=1
ActiveSheet.Select
End If

Else
MsgBox "All worksheets are empty."
End If

' Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
PrintDlg.Delete

' Reactivate original sheet
CurrentSheet.Activate
End Sub

3° Problema. Nelle tue macro di stampa hai inserito
.CenterHeader = "PAGE &P of &N"

Vorrei non ci fosse perché preferisco impostare manualmente (con "imposta
pagina") di volta in volta la posizione del numero di pagina.

Grazie e spero di doverti scocciare più.
Giuseppe
Norman Jones
2006-08-06 17:51:37 UTC
Permalink
Ciao Giuseppe,
Post by Giuseppe
1° Problema. Questa tua Macro mi va benissimo ma........La finestra di
dialogo "seleziona stampante" non funzione bene perché se clicco su "Annulla"
la stampa non viene annullata ma viene lanciata.
Credo che tu abbia mal capito: credo che "Anulla" si riferisca alla scelta
della stampante! Pertanto, cliccando su 'Anulla' non cancella la stampa ma,
invece, cancella la selezione di una stampante; pertanto, lascia la
stampante corrente selezionata.

Se hai bisogno (perche'?) di cancellare anche la stampa, prova a sostituire
Post by Giuseppe
Sheets(arrSheets).PrintOut copies:=1
Sheets(arrSheets).PrintPreview
Il dialogo risultante permetterà che la stampa sia annullato ed inoltre
permetterà la scelta dell''intestazione.
Post by Giuseppe
2° Problema.
Vorrei semplicemnte un'altra macro che mi permetta come questa che ti ho
riportato oltre che di scegliere la stampante di selezionare i Fogli da
stampare così come consente la Macro di John Walkenbach
Ora non capisco in quanto credo che la mia seconda macro (SelectSheets2) ti
permatta proprio di scegliere la stampante e selezionare i fogli da
stampare. L'hai provato?
Post by Giuseppe
3° Problema. Nelle tue macro di stampa hai inserito
.CenterHeader = "PAGE &P of &N"
Vorrei non ci fosse perché preferisco impostare manualmente (con "imposta
pagina") di volta in volta la posizione del numero di pagina.
Ok, niente problema.

Allora, rispondendo ai problemi 1-3, prova a sostituire il codice precedente
con la seguente procedura aggiornata:

'=============>>
Public Sub SelectSheets3()
'John Walkenbach / Norman Jones
Dim i As Long
Dim TopPos As Long
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox
Dim Sheetcount As Long
Dim PreSelezionati As CheckBox
Dim arrSheets As Variant
Dim rng As Range
Dim rCell As Range

Application.ScreenUpdating = False

Set rng = Selection
Set rCell = ActiveCell

arrSheets = Array("Foglio1", "Foglio3", _
"Foglio5', "Fogio99")

' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If

' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add

Sheetcount = 0

' Add the checkboxes
TopPos = 40

For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) <> 0 And _
CurrentSheet.Visible Then
Sheetcount = Sheetcount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(Sheetcount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i

'Creare un nuovo controllo per velocemente
' selezionare i fogli predeterminati
Set PreSelezionati = PrintDlg.CheckBoxes. _
Add(78, TopPos, 150, 16.5)
PreSelezionati.Text = "PreScelti"
TopPos = TopPos + 13

' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240

' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Seleziona Fogli da stampare"
End With

' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront

' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If Sheetcount <> 0 Then
If PrintDlg.Show Then
If PreSelezionati.Value = xlOn Then
Sheets(arrSheets).Select
Else
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Select Replace:=False
End If
Next cb
End If
With Application
.Dialogs(xlDialogPrinterSetup).Show
.Dialogs(xlDialogPageSetup).Show
End With

ActiveWindow.SelectedSheets.PrintOut copies:=1
ActiveSheet.Select
End If
Else
MsgBox "All worksheets are empty."
End If

' Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
PrintDlg.Delete

' Reactivate original sheet
Application.Goto rng
rCell.Activate
End Sub
'<<=============


---
Regards,
Norman
Giuseppe
2006-08-07 17:24:56 UTC
Permalink
Ciao Norman. Sono stato tutto il giorno impegnato a cercare di vedere come
utilizzare al meglio la tua ultima macro.
Vediamo di riepilogare. Non funziona bene:
1) SE IO DALLA FINESTRA IMPOSTA STAMPANTE CLICCO "Annulla" è pur vero quello
che mi dici tu che mi annulla la scelta della stampante ma mi deve fare
ritornare sulla finestra iniziale "Seleziona fogli da stampare" e non
lanciarmi direttamente la stampa senza darmi la possibilità di ripensarci!
2) SE IO DALLA FINESTRA IMPOSTA STAMPANTE SELEZIONO UNA STAMPANTE DIVERSA DA
QUELLA PREDEFINITA la selezione non è immediata come succede nella finestra
"Imposta stampante" di windows. Infatti se dopo averla selezionata vado a
cliìccare su Impostazioni mi rimanda alle impostazioni della stampante
predefinita.
Insomma credo di averti dato un sacco di grane senza essere riuscito a
risolvere il mio problema e mi dispiace molto.

Provo ad aprire un'atra domanda sull'argomento e cercherò di semplificare il
mi problema. Grazie
Post by Norman Jones
'=============>>
Public Sub SelectSheets3()
'John Walkenbach / Norman Jones
Dim i As Long
Dim TopPos As Long
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox
Dim Sheetcount As Long
Dim PreSelezionati As CheckBox
Dim arrSheets As Variant
Dim rng As Range
Dim rCell As Range
Application.ScreenUpdating = False
Set rng = Selection
Set rCell = ActiveCell
arrSheets = Array("Foglio1", "Foglio3", _
"Foglio5', "Fogio99")
' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If
' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add
Sheetcount = 0
' Add the checkboxes
TopPos = 40
For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) <> 0 And _
CurrentSheet.Visible Then
Sheetcount = Sheetcount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(Sheetcount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i
'Creare un nuovo controllo per velocemente
' selezionare i fogli predeterminati
Set PreSelezionati = PrintDlg.CheckBoxes. _
Add(78, TopPos, 150, 16.5)
PreSelezionati.Text = "PreScelti"
TopPos = TopPos + 13
' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240
' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Seleziona Fogli da stampare"
End With
' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront
' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If Sheetcount <> 0 Then
If PrintDlg.Show Then
If PreSelezionati.Value = xlOn Then
Sheets(arrSheets).Select
Else
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Select Replace:=False
End If
Next cb
End If
With Application
.Dialogs(xlDialogPrinterSetup).Show
.Dialogs(xlDialogPageSetup).Show
End With
ActiveWindow.SelectedSheets.PrintOut copies:=1
ActiveSheet.Select
End If
Else
MsgBox "All worksheets are empty."
End If
' Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
PrintDlg.Delete
' Reactivate original sheet
Application.Goto rng
rCell.Activate
End Sub
'<<=============
---
Regards,
Norman
Norman Jones
2006-08-07 17:33:02 UTC
Permalink
Ciao Giuseppe,

Ma non hai visto la mia ultima risposta:

'-------------------
.Dialogs(xlDialogPrinterSetup).Show
.Dialogs(xlDialogPageSetup).Show
con

.Dialogs(xlDialogPrint).Show

'-------------------


---
Regards,
Norman
Norman Jones
2006-08-07 18:31:15 UTC
Permalink
Ciao Giuseppe,
Post by Giuseppe
Ciao Norman. Sono stato tutto il giorno impegnato a cercare di vedere come
utilizzare al meglio la tua ultima macro.
Per riferimento futuro, e per quanto riguarda il mio codice, non dovresti
mai impegnarti per più di alcun minuti; a quel punto dovresti postare un
altro messaggio - sempre nello stesso thread!


---
Regards,
Norman

Giuseppe
2006-08-06 16:45:01 UTC
Permalink
Ancora una cosa che ho notato nella tua macro.
La finestra di dialogo "Imposta stampante" non solo non funziona bene perché
se clicco su "Annulla" la stampa non viene annullata ma eseguita. Ma c'è un
altro problema. Se clicco su "Impostazioni...." mi da la finestra della
stampante predefinita e non di quella selezionata nella finestra stessa.
Grazie
--
Giuseppe
Post by Norman Jones
Ciao Giuseppe,
Post by Norman Jones
Else '<<==
Nuova Riga
Else '<<== Nuova Riga
[La doppia riga e' il lavoro di OE ... :-((]
---
Regards,
Norman
Norman Jones
2006-08-06 18:16:07 UTC
Permalink
Ciao Giuseppe,

Non avevo lett questo quando ho mandato la mia ultima risposta.
Ma c'è un altro problema. Se clicco su "Impostazioni...." mi da
la finestra della stampante predefinita e non di quella selezionata
nella finestra stessa.
Stai utilizzando quale versione di Excel?
.Dialogs(xlDialogPrinterSetup).Show
.Dialogs(xlDialogPageSetup).Show
con

.Dialogs(xlDialogPrint).Show


---
Regards,
Norman
Continua a leggere su narkive:
Loading...