closing as shell application

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,104
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi All

so i use the below to open .pdf files.

VBA Code:
ActiveWorkbook.FollowHyperlink Address:=AdobeFile, NewWindow:=True

Just wondering if i can do it with a shell command.

and close it.


Thanks in advance.

dave
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
The following code will open and then close a file using the Shell function. When the file is opened, the Shell function returns a task or process ID that can be used to later close the file. Then, when closing the file, the Shell function invokes the taskkill command to close it.

Note, since I currently do not have Adobe, I used a Notepad file as an example. But it should work with an Adobe file as well.

VBA Code:
Option Explicit

Sub OpenClose()

    'Open file
    Dim vPID As Variant
    vPID = Shell("C:\Windows\System32\notepad.exe ""C:\users\domenic\desktop\sample.txt""", vbNormalFocus)
    
    'Do stuff here
    
    'Close file
    Call Shell("taskkill /f /pid " & vPID, vbHide)

End Sub

Here's the reference for the Shell function . . .


And here's the reference for the taskkill command . . .


Hope this helps!
 
Upvote 0
Solution
Hi Domenic

Thats great, thanks for that. much appriciated. Very handy.

Dave
 
Upvote 0
Hi Dave,

That's great, glad I could help.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

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
Back
Top