From the Visual Basic Help files of VB Design
http://vbdesign.hypermart.net/cadpages/
Hi all,
I would like to expand on that if I may. This is a lttle demo I cooked up
for you based on the thread so far.
If you open a new project add a user form with a command button (keep the
default names, and the location of the button and size of the form do not
matter, this code will set them for you) then paste this into the code
module of the form, you will get a demo of what Mark is saying. What will
this demo do? It adds a option button to the form for every drawing open in
AutoCAD (so you must be set for MDI) then you can select one of the option
buttons (the drawing name is added to its caption) and click the button. the
selected drawing is now active. It should not take much work to translate
this into your application, but if you need help, by all means let me know.
Option Explicit
Private Sub CommandButton1_Click()
Dim objCtl As Control
Dim strName As String
For Each objCtl In UserForm1.Controls
If TypeOf objCtl Is OptionButton Then
If objCtl.Value = True Then
strName = objCtl.Caption
ThisDrawing.Application.Documents.Item(strName).Activate
objCtl.Caption = "Active Document"
End If
End If
Next
ThisDrawing.Application.Update
End Sub
Private Sub UserForm_Initialize()
Dim objDrawing As AcadDocument
Dim ctlCheckBox As OptionButton
Dim intCnt As Integer
CommandButton1.Left = 2
CommandButton1.top = 2
CommandButton1.Caption = "Make Drawing Active"
CommandButton1.Width = 108
CommandButton1.Height = 20
Me.Width = 120
Me.Height = 50
intCnt = 1
For Each objDrawing In ThisDrawing.Application.Documents
UserForm1.Controls.Move 0, 20
intCnt = intCnt + 1
Set ctlCheckBox = UserForm1.Controls.Add("Forms.OptionButton.1", "Option "
& intCnt, True)
ctlCheckBox.Caption = objDrawing.Name
ctlCheckBox.AutoSize = True
Me.Height = Me.Height + 23
Next
End Sub
Randall Rath
VB Design