Open a file using a non MS office application

  • Thread starter Thread starter mikey2322
  • Start date Start date
M

mikey2322

Guest
Hi,

I am creating a database to file AutoCAD drawings and I have the code below that identifies the file name in the text box and then opens the file using MS word. However, rather than opening the file using MS Word I would like it to open the AutoCAD drawing using the AutoCAD executable located at C:\Program Files\AutoCAD LT 2005\aclt.exe. Any help would be greatly appreciated.


Private Sub cmdOpenWordDoc_Click()

'Check to see that there is a document file path associated with the record
If IsNull(Me.FilePath) Or Me.FilePath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This Document", vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually there
If (Dir(Me.FilePath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location", vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(Me.FilePath)
End If
End If
End Sub

Mike
 
This opens your file with the default registered program in Windows.

Put this in a bas module (in 1 line):

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
Public Const SW_SHOW = 1


'***********************************
'Put this in a command button in your form

ShellExecute Me.hwnd, "open", "C:\Carpeta\Manual.pdf", "", "", SW_SHOW
 
The Shell() function should allow you to open a word doc with the autocad program. Sometimes the Shell() function does not like file paths that contain spaces.

Code:
Call Shell("C:\Program Files\AutoCAD LT 2005\aclt.exe X:\YourWordFile.doc", vbNormalFocus)
 

Users who are viewing this thread

Back
Top Bottom