Add if statement to this macro

jonathann3891

Board Regular
Joined
Apr 27, 2015
Messages
109
I have a macro that will lauch AutoCAD and open a specified drawing.

Is there a way to check if AutoCAD is running, and if so DO NOT open another drawing??

Code:
Public Sub OpnAcad()
 
    Dim strDrawing As String
    On Error Resume Next
    Set Graphics = GetObject(, "AutoCAD.Application")
    If Err.Description > vbNullString Then
        Err.Clear
        Set Graphics = CreateObject("AutoCAD.Application")
    End If
    ' ACAD.Visible = True
    strDrawing = "C:\Users\username\Desktop\test\PileSchedule.dwg"
    Graphics.Documents.Open (strDrawing)
 
    On Error GoTo 0
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Or do you mean by "another drawing" a new document ? If so then see if this works :
Code:
Public Sub OpnAcad()
 
    Dim strDrawing As String
    On Error Resume Next
    Set Graphics = GetObject(, "AutoCAD.Application")
    If Err.Description > vbNullString Then
        Err.Clear
        Set Graphics = CreateObject("AutoCAD.Application")
   [COLOR=#0000ff][B] Else[/B][/COLOR]
        [B][COLOR=#0000ff]Exit Sub[/COLOR][/B]
    End If
    ' ACAD.Visible = True
    strDrawing = "C:\Users\username\Desktop\test\PileSchedule.dwg"
    Graphics.Documents.Open (strDrawing)
 
    On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,060
Messages
6,053,305
Members
444,651
Latest member
markkuznetsov1

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