Prova la segunte macro, da inserire nel file excel:
- Codice: Seleziona tutto
Sub ffemon()
'vedi http://www.pc-facile.com/forum/viewtopic.php?f=26&t=101751
'
Dim ObjWord As Object, objDoc As Object, dDummy
Dim mySk As String, I As Long, Schede As String, FName As String
'
Schede = "schede da stampare.rtf" '<<< Il nome del file da aprire
FName = ThisWorkbook.Path & "\" & Schede
'
Set ObjWord = CreateObject("Word.Application")
ObjWord.Visible = True
Set objDoc = ObjWord.Documents.Open(FName)
'
On Error GoTo 0
If ObjWord Is Nothing Then
MsgBox "Applicazione non disponibile", vbExclamation
End If
'
With ObjWord
SelPrint = .Application.Dialogs(97).Show '97=wdDialogFilePrintSetup
If SelPrint = False Then
MsgBox "Stampa Cancellata"
GoTo ESci
End If
'
For I = 2 To Cells(Rows.Count, 1).End(xlUp).Row
mySk = Cells(I, 1).Value
.Selection.Find.ClearFormatting
With .Selection.Find
.Text = mySk
.Replacement.Text = ""
.Forward = True
.Wrap = 1 '1=wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
If .Selection.Find.Found Then
'se stringa trovata, stampa
pagnr = .Selection.Information(3) '3=wdActiveEndPageNumber
' .Application.PrintOut Filename:="", Range:=wdPrintRangeOfPages, Item:= _
' wdPrintDocumentWithMarkup, Copies:=1, Pages:="5", PageType:= _
' wdPrintAllPages, Collate:=True, Background:=False, PrintToFile:=False, _
' PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
' PrintZoomPaperHeight:=0
dDummy = .Application.PrintOut(False, False, 4, "", , , 7, 1, pagnr & "", 0, False, True, "", , , 0, 0, 0, 0)
Cells(I, 8).ClearContents
Else
'se stringa non trovata, marca in colonna H
Cells(I, 8).Value = mySk & " - Missing"
Beep
End If
Next I
End With
ESci:
dDummy = objDoc.Close(0, 1)
ObjWord.Quit
Set objDoc = Nothing
Set ObjWord = Nothing
'
End Sub
Va lanciata avendo attivo il foglio contenente la lista delle schede da stampare.
Il file contenente tutte le schede deve essere posizionato nella stessa directory in cui e' posizionato il file Excel; il nome file puo' essere impostato tramite l' istruzione marcata <<<.
All' avvio il file Schede viene aperto in una nuova sessione di word; viene chiesto di impostare la stampante da utilizzare per le stampe; infine vengono cercate le schede in sequenza e inviate in stampa. Finito il processo il file Schede viene chiuso e idem l' applicazione Word.
Tieni presente che la colonna H del foglio Ecel viene usata per marcare eventuali schede non trovate.
Prova e fai sapere.