VBA learner ITG
Active Member
- Joined
- Apr 18, 2017
- Messages
- 272
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi Peers,
Can I please get your advice as to why I am getting the above error code when I try to run the below macro which is stopping at this line of code:
I have a licensed version of Adobe Pro DC installed and checked there are no other Adobe readers etc. Also I have made sure the VBA reference Library has the required references.
I have searched different sites and unsure how to approach this.
Can I please get your advice as to why I am getting the above error code when I try to run the below macro which is stopping at this line of code:
I have a licensed version of Adobe Pro DC installed and checked there are no other Adobe readers etc. Also I have made sure the VBA reference Library has the required references.
I have searched different sites and unsure how to approach this.
VBA Code:
Public Sub Merge_PDFs_v2()
Dim strFileExists As String
Dim PDFfiles As Variant
Dim i As Long
Dim objCAcroPDDocDestination As Acrobat.CAcroPDDoc
Dim objCAcroPDDocSource As Acrobat.CAcroPDDoc
ExOffset = 1
Sheets("PDF Maker").Activate
Range("B2").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(@IF(COUNTIF(R2C1:RC[-1],@ultimatelookup(R1C1,R[-1]C,'Store Grades'!R3C3:R3C10,0,1,2))>0,"""",ultimatelookup(R1C1,R[-1]C,'Store Grades'!R3C3:R3C10,0,1,2)),"""")"
Range("B3").Select
Calculate
Sheets("Exceptions").Range("A2:B5000").ClearContents
Sheets("PDF Files").Visible = True
Sheets("PDF Files").Activate
With ActiveSheet
RowCount = Range("W1").Value + 1
RowRange = "A2:S" & RowCount
PDFfiles = Range(RowRange)
End With
Set objCAcroPDDocDestination = CreateObject("AcroExch.PDDoc")
Set objCAcroPDDocSource = CreateObject("AcroExch.PDDoc")
'Loop through rows, open PDF file in column A, open and insert PDF file in column B, save as PDF file in column C
For i = 1 To UBound(PDFfiles)
ExpFilePath = PDFfiles(i, 17)
siteN = PDFfiles(i, 16)
siteC = PDFfiles(i, 19)
deptN = Sheets("PDF Files").Range("U1").Value
deptC = Sheets("PDF Files").Range("U2").Value
outputfile = ExpFilePath & Format(deptC, "00000") & "#" & siteC & "#" & siteN & ".pdf" ' The name of the merged file
sourceopen = 0
destopen = 0
For j = 1 To 15
fname = PDFfiles(i, j)
If Len(PDFfiles(i, j)) = 0 Then
j = 15
Else
strFileExists = Dir(fname)
If strFileExists = "" Then
'MsgBox "The selected file doesn't exist"
Sheets("Exceptions").Range("A1").Offset(ExOffset, 0).Value = siteN
Sheets("Exceptions").Range("A1").Offset(ExOffset, 1).Value = fname
ExOffset = ExOffset + 1
Else
'MsgBox "The selected file exists"
If sourceopen = 0 Then
objCAcroPDDocDestination.Open PDFfiles(i, 1)
sourceopen = 1
Else
objCAcroPDDocSource.Open PDFfiles(i, j)
destopen = destopen + 1
totalopen = destopen + sourceopen
If Not objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0) Then
MsgBox "Error merging" & vbCrLf & PDFfiles(i, 1) & vbCrLf & "and" & vbCrLf & PDFfiles(i, 2), vbExclamation
End If
objCAcroPDDocSource.Close
End If
End If
End If
Next
Debug.Print outputfile
objCAcroPDDocDestination.Save 1, outputfile
objCAcroPDDocDestination.Close
Next
Set objCAcroPDDocSource = Nothing
Set objCAcroPDDocDestination = Nothing
MsgBox "Done"
Sheets("PDF Files").Visible = False
End Sub