2016-05-31 91 views
5
Sheets("Key Indicators").ExportAsFixedFormat Type:=xlTypePDF, 
Filename:=ArchivePath, Quality:=xlQualityStandard, 
IncludeDocProperties:=True, IgnorePrintAreas _ 
     :=False, OpenAfterPublish:=False 

Attualmente questo è quello che ho.Utilizzo di VBA come richiamare la funzione Adobe Create PDF

Capisco come ExportAsFixedFormat PDF, ma quello che devo sapere come fare è accedere alla funzione Crea PDF in Acrobat (come mostrato nella foto sotto) usando VBA. Se eseguo ExportAsFixedFormat, i collegamenti vengono appiattiti. Acrobat "Crea PDF" mi permetterebbe di convertire un Excel in PDF con i collegamenti ipertestuali inclusi.

AdobePDFMakerForOffice

Come dovrei farlo?

Sto usando Excel 2016 e Adobe Pro DC

enter image description here Questi sono i miei Adobe fa riferimento

+2

Il componente aggiuntivo Acrobat fornisce un'API? un modello a oggetti? * qualsiasi cosa * programmaticamente accessibile da VBA? In caso contrario, potrebbe essere necessario ricorrere a * SendKeys *, che è un modo orribile e orribile di fare le cose. Cosa c'è di sbagliato con il salvataggio in PDF? Cosa fa il componente aggiuntivo Adobe che Excel non ha già? –

+0

Se si salva come PDF normalmente si appiattiscono tutti i collegamenti nel documento. –

+1

[Questo] (http://superuser.com/a/921280/165271) potrebbe aiutare –

risposta

1

Acrobat riferimento dovrebbe funzionare
Here is the guide from Adobe
Una volta aggiunto, è possibile utilizzare il seguente codice Suggerimento: potrebbe indurti a correggere il codice. Non sono sicuro di averlo codificato "alla cieca" perché non ho Acrobat nel mio PC. Fai il debug passo dopo passo per vedere cosa sta facendo.

Sub ExportWithAcrobat() 
Dim AcroApp As Acrobat.CAcroApp 'I'm not quite sure it's needed since we are creating the doc directly 
Dim AcrobatDoc As Acrobat.CAcroPDDoc 
Dim numPages As Long 
Dim WorkSheetToPDF As Worksheet 
Const SaveFilePath = "C:\temp\MergedFile.pdf" 
    Set AcroApp = CreateObject("AcroExch.App") 'I'm not quite sure it's needed since we are creating the doc directly 
    Set AcrobatDoc = CreateObject("AcroExch.PDDoc") 
    'it's going to be 0 at first since we just created 
    numPages = AcrobatDoc.GetNumPages 
    For Each WorkSheetToPDF In ActiveWorkbook.Worksheets 
    If AcrobatDoc.InsertPages(numPages - 1, WorkSheetToPDF, 0, AcrobatDoc.GetNumPages(), True) = False Then 'you should be available to work with the code to see how to insert the sheets that you want in the created object ' 1. If Part1Document.InsertPages(numPages - 1, "ExcelSheet?", 0, AcrobatDoc.GetNumPages(), True) = False 
    MsgBox "Cannot insert pages" & numPages 
    Else ' 1. If Part1Document.InsertPages(numPages - 1, "ExcelSheet?", 0, AcrobatDoc.GetNumPages(), True) = False 
    numPages = numPages + 1 
    End If ' 1. If Part1Document.InsertPages(numPages - 1, "ExcelSheet?", 0, AcrobatDoc.GetNumPages(), True) = False 
    Next WorkSheetToPDF 
    If AcrobatDoc.Save(PDSaveFull, SaveFilePath) = False Then ' 2. If Part1Document.Save(PDSaveFull, "C:\temp\MergedFile.pdf") = False 
    MsgBox "Cannot save the modified document" 
    End If ' 2. If Part1Document.Save(PDSaveFull, "C:\temp\MergedFile.pdf") = False 
End Sub 

pagine seguenti possono fornire una migliore assistenza: Link1, Link2

+0

Viene visualizzato l'errore "Impossibile inserire pagine- 1" –

+1

Fare riferimento alla documentazione e provare a "riprodurre" combinandoli con i codici forniti in basso, non è possibile programmare ulteriormente poiché non si dispone di Acrobat. – Sgdva

1
With ActiveSheet 
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:="N:\JKDJKDJ", _ 
    Quality:=xlQualityStandard, IncludeDocProperties:=True, 
    IgnorePrintAreas:=False, OpenAfterPublish:=False 
End With 
+0

vale la pena notare che i miei collegamenti non vengono appiattiti quando si utilizza questo approccio – jellz77

+0

Sono collegamenti ipertestuali tra i fogli di lavoro? –

2
Sub PDF() 
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ 
     "C:\Users\PCNAME\Documents\Book1.pdf", Quality:=xlQualityStandard, _ 
     IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _ 
    True 
End Sub 

Prova codici di cui sopra

+0

Il problema è che senza richiamare Adobe, i collegamenti ipertestuali non vengono trasferiti in PDF –

1

È possibile pubblicare qualsiasi intervallo Excel come PDF utilizzando ExportAsFixedFormat. Non è necessario impostare un riferimento ad Acrobat.

' Usage: 
' PublishRangePDF(Thisworkbook, fileName) : Will Publish the entire Workbook 
' PublishRangePDF(AvtiveSheet, fileName) : Will Publish all selected worksheets 
' PublishRangePDF(Range("A1:H100"), fileName) : Will Publish Range("A1:H100") 


Sub PublishRangePDF(RangeObject As Object, fileName As String, Optional OpenAfterPublish As Boolean = False) 
    On Error Resume Next 
    RangeObject.ExportAsFixedFormat Type:=xlTypePDF, fileName:=fileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=OpenAfterPublish 
    On Error GoTo 0 
End Sub 
+0

Il problema è che senza richiamare Adobe, i collegamenti ipertestuali non vengono trasferiti ai collegamenti ipertestuali URL PDF –

+0

per me. I collegamenti ipertestuali dei segnalibri vengono appiattiti. jellz77 usa ExportAsFixedFormat anche tu hai detto che non li appiattisce.Se puoi mandarmi la tua cartella di lavoro, prenderò molto. Se no, puoi pubblicare il resto se il tuo codice? –

+0

I collegamenti ipertestuali dei segni del libro che voglio mantenere. –

Problemi correlati