Actuarial Outpost
 
Go Back   Actuarial Outpost > Actuarial Discussion Forum > Software & Technology
FlashChat Actuarial Discussion Preliminary Exams CAS/SOA Exams Cyberchat Around the World Suggestions


Fill in a brief DW Simpson Registration Form
to be contacted when our jobs meet your criteria.


Reply
 
Thread Tools Display Modes
  #1  
Old 11-29-2011, 10:29 AM
chicken_po_boy's Avatar
chicken_po_boy chicken_po_boy is offline
Member
CAS
 
Join Date: Nov 2008
Location: 401 Poydras New Orleans, LA 70130
Studying for CAS 9
College: been there, done that
Favorite beer: You gonna finish that?
Posts: 1,562
Default Using VBA to create/append to PDF

I'm a hack at VBA and I could use some help. I have macros like this:

MacroA()
set up
prints selection A to printer
End

MacroB()
set up
prints selection B to printer
End

MacroC()
set up
prints selection C to printer
End

Then I have another macro called "PrintAll"...

Macro PrintAll
call MacroA()
call MacroB()
call MacroC()
End

(The real situation is more complex than this.)

I want to change PrintAll to save everything to a single PDF rather than print to the printer. However, I only want a PDF if running PrintAll. If running individial A/B/C macros (by themselves) I want them to continue printing to the printer as they currently do.

For creating the PDF, I want to utilize the print setups within MacroA, MacroB, and MacroC so I still want to call those macros from PrintAll. I'm halfway there. I changed the macros like this:

Macro PrintAll
All = 1
call MacroA(All)
call MacroB(All)
call MacroC(All)
All = 0
End

MacroA(All)
set up
If All = 1
save as .pdf
Else
prints selection A to printer
End If
End

MacroB and MacroC are similar to MacroA.

This is correctly printing to printer when running the individual macros, and making PDF's when running the PrintAll macro. Problem is... the PDF's are individual documents. I don't know how to combine the PDF's into a single document. Is there a way to have VBA "append" to a PDF? Or, is there a way to write to a PDF, leave it open, and write some more before saving/closing?
Reply With Quote
  #2  
Old 11-29-2011, 10:53 AM
llcooljabe's Avatar
llcooljabe llcooljabe is online now
Member
CAS
 
Join Date: Aug 2002
Favorite beer: Rickard's Red
Posts: 14,644
Default

I tried something similar years ago. I posted in the MrExcel.com message boards: http://www.mrexcel.com/forum/showthread.php?t=297737

I never ended up using the suggested solutions, but check them out.
__________________
www.GoodNewsNow.info
Propoganda
Reply With Quote
  #3  
Old 11-29-2011, 10:55 AM
Chuck Chuck is offline
Member
SOA AAA
 
Join Date: Oct 2001
Location: Illinois
Posts: 2,254
Default

Write all the selections to another document (say a Word doc or another Excel tab with page breaks) and then print that document?
Reply With Quote
  #4  
Old 11-29-2011, 01:06 PM
chicken_po_boy's Avatar
chicken_po_boy chicken_po_boy is offline
Member
CAS
 
Join Date: Nov 2008
Location: 401 Poydras New Orleans, LA 70130
Studying for CAS 9
College: been there, done that
Favorite beer: You gonna finish that?
Posts: 1,562
Default

I found some code on the internet to append PDF's but it is not working for me, grrr... Here is where I found the code:

http://www.vbaexpress.com/forum/showthread.php?t=21610

I'm getting an error message "Run-time error '429': ActiveX component can't create object" (whatever the heck that means)

I'm attaching a watered-down version sample file to illustrate the problem. It will create two .pdf's and save them (create a C:\temp directory before running so it can save them there). But then it crashes when I try to use the function to append them together. Can anyone help? I feel like I'm so close... Thanks!!

P.S. "PrintA" will print Tab A to the printer and "PrintB" will print Tab B to the printer (just how I want it). "PrintAll" should create a .pdf of both; this is the part that's not working.
Attached Files
File Type: xlsm example.xlsm (19.4 KB, 34 views)

Last edited by chicken_po_boy; 11-29-2011 at 01:11 PM.. Reason: added P.S.
Reply With Quote
  #5  
Old 11-29-2011, 02:12 PM
dumples dumples is offline
Member
 
Join Date: Sep 2003
Posts: 1,073
Default

Quote:
Originally Posted by chicken_po_boy View Post
I found some code on the internet to append PDF's but it is not working for me, grrr... Here is where I found the code:

http://www.vbaexpress.com/forum/showthread.php?t=21610

I'm getting an error message "Run-time error '429': ActiveX component can't create object" (whatever the heck that means)

I'm attaching a watered-down version sample file to illustrate the problem. It will create two .pdf's and save them (create a C:\temp directory before running so it can save them there). But then it crashes when I try to use the function to append them together. Can anyone help? I feel like I'm so close... Thanks!!

P.S. "PrintA" will print Tab A to the printer and "PrintB" will print Tab B to the printer (just how I want it). "PrintAll" should create a .pdf of both; this is the part that's not working.
Did you add a reference to the appropriate library? From a little bit of googling of "AcroExch", I think that should be the "Adobe Acrobat Type Library", but I don't have that in my reference list (I do have Acrobat 8 installed on this computer). I have a few things that look like it, but I'm not going to mess around with this for you.

To access references, Go to the VBA editor, Tools>References
Reply With Quote
  #6  
Old 11-29-2011, 02:15 PM
dumples dumples is offline
Member
 
Join Date: Sep 2003
Posts: 1,073
Default

Try adding the "Acrobat" reference and let me know if that code works.
Reply With Quote
  #7  
Old 11-29-2011, 02:21 PM
dumples dumples is offline
Member
 
Join Date: Sep 2003
Posts: 1,073
Default

In your code, you have a line that says:
"Dim Final As Object"

change that to
"Dim Final As Boolean"

Then it works for me without messing with any references, just the 4 that are usually there.
Reply With Quote
  #8  
Old 11-29-2011, 02:25 PM
dumples dumples is offline
Member
 
Join Date: Sep 2003
Posts: 1,073
Default

These are the 4 references I have.

I am using office 2010 and I have adobe acrobat installed on my computer. I'm not sure if that makes a difference.
Attached Images
 
Reply With Quote
  #9  
Old 11-29-2011, 02:42 PM
chicken_po_boy's Avatar
chicken_po_boy chicken_po_boy is offline
Member
CAS
 
Join Date: Nov 2008
Location: 401 Poydras New Orleans, LA 70130
Studying for CAS 9
College: been there, done that
Favorite beer: You gonna finish that?
Posts: 1,562
Default

I added a whole bunch of references (anything that looked like it might have something to do with Acrobat), but unfortunately it is still not working. This is new territory for me... Do I need to have the full version of Acrobat? I only have the reader version.
Attached Images
 
Reply With Quote
  #10  
Old 11-29-2011, 02:54 PM
chicken_po_boy's Avatar
chicken_po_boy chicken_po_boy is offline
Member
CAS
 
Join Date: Nov 2008
Location: 401 Poydras New Orleans, LA 70130
Studying for CAS 9
College: been there, done that
Favorite beer: You gonna finish that?
Posts: 1,562
Default

I just tried it on someone else's computer (who has the full version of Acrobat) and it worked. Thanks!!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT -4. The time now is 12:33 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
*PLEASE NOTE: Posts are not checked for accuracy, and do not
represent the views of the Actuarial Outpost or its sponsors.
Page generated in 0.30985 seconds with 10 queries