Macro per inserire immagini in Word 2007 e creare automaticamente un PDF

Sfruttando gli ultimi 2 post: Macro per utilizzare lo scanner da Word 2007 e Esportare un documento Office 2007 in PDF, ho leggermente automatizzato il procedimento aziendale di “scansione, inserimento immagni, esportazione in PDF”.

Tutta la procedura viene svolta da una semplice macro:

 

Sub Crea_PDF()
'
' Crea_PDF Macro
' Riduce i margini del foglio.
    With Selection.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.27)
        .BottomMargin = CentimetersToPoints(1.27)
        .LeftMargin = CentimetersToPoints(1.27)
        .RightMargin = CentimetersToPoints(1.27)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
    End With
    
' Scannerizza le immagini.
On Error Resume Next
WordBasic.InsertImagerScan
          
' Esporta in PDF.
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        "C:\Documents and Settings\Andrea\Desktop\Doc1.pdf", ExportFormat:= _
        wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
        
        ' Messaggio di notifica.
        MsgBox "Creazione del file PDF completata.", vbInformation, "Crea PDF"
                 
' Chiude Word chiedendo conferma.
Application.Quit

End Sub

 

NB: In questo caso il file PDF viene generato nel “C:\Documents and Settings\Andrea\Desktop”, sempre col solito nome (Doc1.pdf). Questa è una soluzione rapida per chi, come me, crea dei semplici file temporanei. E’ invece possibile personalizzare i nomi dei file inserendo ad esempio una inputbox prima dell’esportazione.

 

Print | posted on martedì 9 marzo 2010 10.56

Feedback

No comments posted yet.

Your comment:





 
Please add 3 and 1 and type the answer here:

Copyright © Andrea Zingoni

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski