Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launching SolidWroks from the Command Line

Status
Not open for further replies.

jwalz

Computer
Apr 22, 2003
10
0
0
US
Is there a way to launch SolidWorks from the command line? I have an Access database with lists of drawing files in it. I want to be able to have a user click on the drawing name and have solidworks open the file automatically.
My VBA code currently looks like this:

Private Sub DrawingName_DblClick(Cancel As Integer)
'Open solidworks with the appropriate drawing
strFilename = Me.DrawingFile
x = Shell(strFilename, 1)
End Sub

But I get an error message that says "invalid file or procedure call." The file name variable contains the full path information. Can anyone tell me what I am doing wrong or make suggestions?

Thanks,
Janet
 
Replies continue below

Recommended for you

As I understand it, shell is used to activate applications.

I once saw some code to open a file with its default application, but I can't seem to find it. If I run across it I will post.

In the meantime, try using shell to open the SW, then access the SW application object via CreateObject and use it to open the file via SW API.

[bat]All this machinery making modern music can still be open-hearted.[bat]
 
Yes, that's the one. If you use the "Open" verb as its verb parameter, ShellExecute will use the same command-line type of default behavior that you get when you do a right-click Open on the filename from Windows Explorer. (You can see the syntax for these command lines in the registry)

Remember to declare the functions you will be using:
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Const SW_SHOWNORMAL = 1

And then you can make use of the function something like this:
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", sDocName, "", "C:\", SW_SHOWNORMAL)

Regards,
Brenda
 
Status
Not open for further replies.
Back
Top