VB6 Code Help..

Thread Starter

Engr

Joined Mar 17, 2010
114
Hi Guys,

I am making a code in VB6 that will combine the 2 PDF Files. This is the code that I just copied in the internet:

Private Sub Command1_Click()
Me.MousePointer = 11
Dim origPdfDoc As Acrobat.CAcroPDDoc
Dim newPdfDoc As Acrobat.CAcroPDDoc
Dim path As String
Dim path2 As String
Dim varNewTotalPages As Long

path = "C:\Users\joem\Desktop\Databook\New Folder\3.pdf"
path2 = "C:\Users\joem\Desktop\Databook\New Folder\4.pdf"
Set origPdfDoc = CreateObject("AcroExch.PDDoc")
Set newPdfDoc = CreateObject("AcroExch.PDDoc")

If origPdfDoc.Open(path) Then
If newPdfDoc.Open(path2) Then
'Get total # of pages too insert
varNewTotalPages = newPdfDoc.GetNumPages
'Insert pages into original pdf
origPdfDoc.InsertPages True, newPdfDoc, 0, varNewTotalPages, False
'Save doc
origPdfDoc.Save PDSaveIncremental, path
Else
MsgBox "Failed to open doc " & path2
End If

'Close docs
origPdfDoc.Close
newPdfDoc.Close
MsgBox "Pages added to " & path
Else
MsgBox "Failed to add pages to " & path
End If

Set origPdfDoc = Nothing
Set newPdfDoc = Nothing
Me.MousePointer = 0
End Sub

I already check the "Adobe Acrobat 9.0 Type Library" but every time I run the program I am always getting this error "ActiveX component can't create object"...Can anybody help me how to solve this?....See attached file for the actual error
 

Attachments

kingdano

Joined Apr 14, 2010
377
:eek:

i never thought id see someone using VB6 for that...people who i have spoken to tend to talk down the capabilities of VB in general - at least up until the latest release which ive heard is more like C++

i cant help you with that particular problem - but maybe you should try writing a program to simply combine two static .pdf files instead of opening them, and dealing with all of the processing of page numbers...just try to break the program down into more manageable chunks before throwing it all together...that seems to work well for me.
 

BMorse

Joined Sep 26, 2009
2,675
Is the DLL you are using properly registered? And are you licensed (or does it have a free license) for you to use it in your own program??

B. Morse
 

bluebrakes

Joined Oct 17, 2009
252
try putting at the very top after the private sub line...

on error resume next

and see what it does, does it do anything?

Also you have stated what the final file name should be? is that right?
 

BMorse

Joined Sep 26, 2009
2,675
:eek:

i never thought id see someone using VB6 for that...people who i have spoken to tend to talk down the capabilities of VB in general - at least up until the latest release which ive heard is more like C++
I actually use VB6 for a lot of tasks people say can only be done with C or C++.... I write almost all my PC based automation software in VB6, which is installed and running all over Michigan, and other states (and a few parts of Canada)...

B. Morse
 

Thread Starter

Engr

Joined Mar 17, 2010
114
Yes, my VB6 is licensed. I place the "on error resume next" command and placed a msgbox after getting the number of pages to be added command but it is displaying "0"...See below for the updated program....

Private Sub Command1_Click()
On Error Resume Next 'remove this once the program is ready
Me.MousePointer = 11
Dim origPdfDoc As Acrobat.CAcroPDDoc
Dim newPdfDoc As Acrobat.CAcroPDDoc
Dim path As String
Dim path2 As String
Dim path3 As String
Dim varNewTotalPages As Long

path = "C:\Users\joem\Desktop\datasheet.pdf"
path2 = "C:\Users\joem\Desktop\Boolean.pdf"
path3 = "C:\Users\joem\Desktop\Sample.pdf"
Set origPdfDoc = CreateObject("AcroExch.PDDoc")
Set newPdfDoc = CreateObject("AcroExch.PDDoc")

If origPdfDoc.Open(path) Then
If newPdfDoc.Open(path2) Then
'Get total # of pages too insert
varNewTotalPages = newPdfDoc.GetNumPages
'varNewTotalPages = origPdfDoc.GetNumPages
MsgBox varNewTotalPages 'added to get the value of varNewTotalPages
'Insert pages into original pdf
origPdfDoc.InsertPages True, newPdfDoc, 0, varNewTotalPages, False
'Save doc
origPdfDoc.Save PDSaveIncremental, path3
Else
MsgBox "Failed to open doc " & path2
End If

'Close docs
origPdfDoc.Close
newPdfDoc.Close
MsgBox "Pages added to " & path3
Else
MsgBox "Failed to add pages to " & path3
End If

Set origPdfDoc = Nothing
Set newPdfDoc = Nothing
Me.MousePointer = 0
End Sub
 

retched

Joined Dec 5, 2009
5,207
Do us a favor and use the code tags around your code, It helps keep everything easy on the eyes, and brain.

http://forum.allaboutcircuits.com/showthread.php?t=37117

you can edit your previous posts and easily edit them.. Also if you click 'Go Advanced' there will be a '#' option in the editor that will auto code-tag your highlighted code, or you can press it then paste the code between the open and close CODE tags.
 

Thread Starter

Engr

Joined Mar 17, 2010
114
Private Sub Command1_Click()
On Error Resume Next 'remove this once the program is ready
Me.MousePointer = 11
Dim origPdfDoc As Acrobat.CAcroPDDoc
Dim newPdfDoc As Acrobat.CAcroPDDoc
Dim path As String
Dim path2 As String
Dim path3 As String
Dim varNewTotalPages As Long

path = "C:\Users\joem\Desktop\datasheet.pdf"
path2 = "C:\Users\joem\Desktop\Boolean.pdf"
path3 = "C:\Users\joem\Desktop\Sample.pdf"
Set origPdfDoc = CreateObject("AcroExch.PDDoc")
Set newPdfDoc = CreateObject("AcroExch.PDDoc")

If origPdfDoc.Open(path) Then
If newPdfDoc.Open(path2) Then
'Get total # of pages too insert
varNewTotalPages = newPdfDoc.GetNumPages
'varNewTotalPages = origPdfDoc.GetNumPages
MsgBox varNewTotalPages 'added to get the value of varNewTotalPages
'Insert pages into original pdf
origPdfDoc.InsertPages True, newPdfDoc, 0, varNewTotalPages, False
'Save doc
origPdfDoc.Save PDSaveIncremental, path3

Else
MsgBox "Failed to open doc " & path2​
End If

'Close docs
origPdfDoc.Close
newPdfDoc.Close
MsgBox "Pages added to " & path3

Else
MsgBox "Failed to add pages to " & path3
End If

Set origPdfDoc = Nothing
Set newPdfDoc = Nothing
Me.MousePointer = 0

End Sub



.......Hope this helps
 

kingdano

Joined Apr 14, 2010
377
I actually use VB6 for a lot of tasks people say can only be done with C or C++.... I write almost all my PC based automation software in VB6, which is installed and running all over Michigan, and other states (and a few parts of Canada)...

B. Morse
**not trying to thread-jack**

i love vb6 beacuse it is easy, and error-friendly (re-naming of variables, built in functionality etc)

i have done parallel port comms, serial comms and basic user front-ends with it myself.

it really is good for a software beginner like me.

again, sorry for the OT post
 

retched

Joined Dec 5, 2009
5,207
Thats what I was speaking of also... I thought it was obvious, but I guess we should have clairified. Without the licenced Adobe DLL, it WILL NOT create a pdf. You can open for view all day long. But cannot write to them.
 

kingdano

Joined Apr 14, 2010
377
Where can I get a licensed Adobe DLL.?
In order to use the adobe .dll properly you'll need to purchase adobe acrobat professional. by having this software, you have the right (from adobe) to create new .pdf files.

Do you understand what we are saying?
 
Did you include the library in the project references and are you licensed to use the library? I'm asking if you have the license for the library itself, not VB.

*Edit* N/m someone already asked.
 
Top