View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default close a pdf file opened via shellexecute

I am using the following code to open a pdf file.

Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

strFile = 'assume strFile is opening without issue

ShellExecute 0, "open", strFile, vbNullString, vbNullString, 0



how can I close the PDF file with vba script? Thank you in advance!


You need to know the name of the app that opens PDFs, and determine
what its window 'title' is so you can grab its 'handle'. Once done you
can send it a close message. You could simple query open windows for
determining which has the filename in its 'title'; -obviates needing to
know which app opens PDFs on another machine if your project runs
there.

I have code that runs an out-of-process EXE as though it was
in-process. It locates the window and grabs its handle so that EXE ends
when my project shuts down. I can dig for the exact code and post
back...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion