Close a PDf Through Automation... so close to finishing!!

Kavy

Well-known Member
Joined
Jun 25, 2007
Messages
607
Hello,

So as in another thread I posted I am getting an error msg during runtime which I belive it only occurs becuase I can't close my pdf's I am automating.

Below are the objects I create, and how I am attempting to close them, I have been googling and can't figure this out! While the pdf is hidden, if I check my memory usuage it is still sucking up memory!

<code>
Objects Created:
Set gapp = CreateObject("AcroExch.App")
Set gAvDoc = CreateObject("AcroExch.AVDoc")
Set gpdDoc = CreateObject("AcroExch.PDDoc")
gpdDoc.Open(strfiLe) And gAvDoc.Open(strfiLe, strfiLe & "temp")
Set jso = gpdDoc.GetJSObject
set Aform = CreateObject("AFormAut.App")

'And now my attempt at closing, they all dont cause errors unless noted
gapp.Exit
gapp.CloseAllDocs
gAvDoc.Exit 'Causes an error in Runtime
gpdDoc.Close
Aform.Exit 'Also causes an error in runtime

Set gAvDoc = Nothing
Set pdDoc = Nothing
Set Aform = Nothing
Set jso = Nothing

</code>

Does anyone know how to finish off killing this pdf? Thank you
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Kavy

Well-known Member
Joined
Jun 25, 2007
Messages
607
So I manage to find a way to close all the variables open, as far as I can tell, but Adobe is still open in my task manager! Does anyone have a any ideas?

For those wondering, I closed gAvDoc by going "gAvDoc.Close (True) and the Aform, well it turns out I wasnt using it so I just deleted the line.
 

tweedle

Well-known Member
Joined
Aug 1, 2010
Messages
1,559
Seems like exiting gapp and then calling a closealldocs might be a problem.
What does it do when you exit the objects in the inverse order they were created?

i.e.:
Aform.Exit 'Also causes an error in runtime
'anything to close for jso object?
gpdDoc.Close
gAvDoc.Exit 'Causes an error in Runtime
gapp.CloseAllDocs

gapp.Exit

 

Kavy

Well-known Member
Joined
Jun 25, 2007
Messages
607
Thanks for the reply tweedle.

It didnt work, but it was worth a shot, I sm up for trying anything! The worse part is I dont know if it will fix my problem from the other thread! I think the gapp.CloseAllDocs and gapp.exit may be mutually exlusive.

Anyway, here is how it is layout now:

<code>
gpdDoc.Close
gAvDoc.Close (True)
gapp.CloseAllDocs
gapp.Exit

Set gapp = Nothing
Set gAvDoc = Nothing
Set pdDoc = Nothing
Set jso = Nothing

</Code>
 

james_lankford

Well-known Member
Joined
Jan 11, 2009
Messages
1,172

ADVERTISEMENT

<code>the AND in here doesn't do anything
gpdDoc.Open(strfiLe) And gAvDoc.Open(strfiLe, strfiLe & "temp")
are you meaning to test if the files opened ?

are you sure there is an Exit method for the </code><code>gAvDoc object ?
</code><code>gAvDoc.Exit 'Causes an error in Runtime</code>

perhaps you're calling a method that doesn't exist
<code>
</code>
 

tweedle

Well-known Member
Joined
Aug 1, 2010
Messages
1,559
My final iteration to try (I'm not largely familiar with Acro Objects, but they're still objects, right?):

Code:
Aform.Exit  
set jso = Nothing ' May need to clear b/c member of gpdDoc
gpdDoc.Application.Exit
gAvDoc.Application.Exit  
gapp.Exit
I'm not understanding the 'And' in this:
gpdDoc.Open(strfiLe) And gAvDoc.Open(strfiLe, strfiLe & "temp")
 

Kavy

Well-known Member
Joined
Jun 25, 2007
Messages
607

ADVERTISEMENT

Sorry James and Tweedle,

I used the "And" in an "If, Then" statment to open the two objects (I think??)

The gAvDoc I manage to close (or at least not get an error during runtime) by going gAvDoc.close (True).

With all this Acrobat stays in my process window sucking memory when I pause the code after my close statments.

Thanks,

Kavy
 

Kavy

Well-known Member
Joined
Jun 25, 2007
Messages
607
Thanks for the idea Tweedle, but no luck.. Acrobat.exe is still open in my task manager process.

The application.exit caused runtime errors. I re-arragne the set jso = nothing line to the top but no luck.

Thanks for all your comments!
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,572
Messages
5,512,115
Members
408,881
Latest member
Pooxie

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top