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
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

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,207

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!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,571
Messages
5,832,566
Members
430,142
Latest member
ivonsurf123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top