Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA - opening files with Shell command

I'm writing a macro in Excel which finds other files (not Excel files)
with a given name and then opens them. I'm using the Windows registry
to find the programs associated with the files and then using the Shell
command to open the files with the given program. My problem is that
for some programs the Shell command opens a new instance of the program
for each additional file, i.e. each AutoCAD file opens into its own
instance of AutoCAD even if AutoCAD is already running.

So my question is, is there a switch for the Shell command that tells
it to check to see if an instance of a program is already running
before starting a new one, and, if the program is already running,
opens the file with the existing instance? Or is there another way of
doing this without getting into the API of each program in question?

Here's a snippet of my code:

strCmd = appWord.System.PrivateProfileString("", _
"HKEY_CLASSES_ROOT\" & regType & "\shell\Open\command", _
"")

If Len(strCmd) 0 Then
strCmd = Replace(strCmd, "%1", fileWithPath) 'for pdf & dwg files
strCmd = Replace(strCmd, "/dde", "/one " & """" & fileWithPath &
"""") 'for solidworks files
Shell strCmd, vbNormalFocus
Else
MsgBox prompt:="Could not find an application" & vbCr & _
"registered to display file.", _
Buttons:=vbCritical + vbOKOnly, _
Title:="Not Registered"
End If


Thanks!
Eric

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default VBA - opening files with Shell command

Some applications just run one file at a time. Think of Excel - you can open
multiple workbooks in one application instance, but then think of MS Paint -
one file at a time. You should check to see if the application supports
multiple open documents.

You can try and create the application using GetObject / CreateObject if you
know the name of the application class - like Excel.Application.10 for an
Excel v10 instance.


--
www.alignment-systems.com


"Eric" wrote:

I'm writing a macro in Excel which finds other files (not Excel files)
with a given name and then opens them. I'm using the Windows registry
to find the programs associated with the files and then using the Shell
command to open the files with the given program. My problem is that
for some programs the Shell command opens a new instance of the program
for each additional file, i.e. each AutoCAD file opens into its own
instance of AutoCAD even if AutoCAD is already running.

So my question is, is there a switch for the Shell command that tells
it to check to see if an instance of a program is already running
before starting a new one, and, if the program is already running,
opens the file with the existing instance? Or is there another way of
doing this without getting into the API of each program in question?

Here's a snippet of my code:

strCmd = appWord.System.PrivateProfileString("", _
"HKEY_CLASSES_ROOT\" & regType & "\shell\Open\command", _
"")

If Len(strCmd) 0 Then
strCmd = Replace(strCmd, "%1", fileWithPath) 'for pdf & dwg files
strCmd = Replace(strCmd, "/dde", "/one " & """" & fileWithPath &
"""") 'for solidworks files
Shell strCmd, vbNormalFocus
Else
MsgBox prompt:="Could not find an application" & vbCr & _
"registered to display file.", _
Buttons:=vbCritical + vbOKOnly, _
Title:="Not Registered"
End If


Thanks!
Eric


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA - opening files with Shell command

Thanks for the reply.

The applications in question do support multiple open documents. I'm
trying to duplicate the behavior of Windows Explorer -- if you open an
AutoCAD or Solidworks file (two of the applications in question) by
double-clicking the file, Windows either starts an instance of the
program if one isn't running already, or opens the file into an
existing instance if it is. Also, I'm trying to avoid going the
GetObject / CreateObject route since my macro needs to work over a wide
range of file types and programs.

Any more ideas?

Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA - opening files with Shell command

try using this

Shell ("Start C:\Bridge Scorer\Manual.doc")


--
Regards,
Tom Ogilvy


"Eric" wrote in message
oups.com...
Thanks for the reply.

The applications in question do support multiple open documents. I'm
trying to duplicate the behavior of Windows Explorer -- if you open an
AutoCAD or Solidworks file (two of the applications in question) by
double-clicking the file, Windows either starts an instance of the
program if one isn't running already, or opens the file into an
existing instance if it is. Also, I'm trying to avoid going the
GetObject / CreateObject route since my macro needs to work over a wide
range of file types and programs.

Any more ideas?

Thanks!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell command and Notepad SA3214 Excel Programming 1 May 15th 05 11:57 AM
Shell Command JOHN Excel Programming 1 November 17th 04 10:39 AM
Shell command MAx Excel Programming 2 June 4th 04 04:11 PM
xp shell command using vba Sudhendra Excel Programming 2 February 16th 04 05:56 AM
SHELL command Robin Clay[_3_] Excel Programming 3 October 17th 03 02:50 PM


All times are GMT +1. The time now is 08:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"