PDA

View Full Version : Opening an AutoCAD template from Excel with VBA



bobkat
11-29-2012, 07:52 PM
I found this bit of code http : / / www . vbaexpress . com /kb /getarticle .php (sorry but first post so can't insert a link :dunno ) that when I made a slight change I was able to open a AutoCAD template file:beerchug:

Only problem is that it opens 2 of them. Can anyone see the reason why it is doing this?

Option Explicit

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

Function OpenAnyFile(FileToOpen As String)

Call ShellExecute(0, "Open", FileToOpen & vbNullString, _
vbNullString, vbNullString, 1)

End Function

Sub Example()

Call OpenAnyFile("I:\Support\Drafting\Drawing Templates\Skid.dwt")

End Sub


Regards

Bob