Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Mary,
Looks like GetObject is failing because there is no instance of Excel running, so you are creating a new empty instance, even though that code is commented out in your sample. Also, whilst not the cause your problem, it would be better to use something like "XLApp" instead of "excel" for the variable name. Assuming ACAD VBA behaves the same as in Office, this line really means nothing: If Err<0 Then because you have no "On Error Resume Next" before GetObject. So if there is an error, it will not be handled. So basically your is code is working (after you add "On Error Resume Next"). But because you need to work with the current XL file, you should exit your code if GetObject fails, because you have nothing to work with. Also, you do know that if you have more than 1 instance of Excel running, GetObject will give access to 1 instance essentially at random. So you may not get the reference to workbook you desire. NickHK wrote in message oups.com... Here is the code Mary ---------- Dim rng As Range Dim excel As Object Dim acad As Object -------- Excess code cut ------------- Private Sub CommandButton1_Click() EXAMPLE_GETVARIABLE Set excel = GetObject(, "Excel.Application") If Err < 0 Then Err.Clear 'Set excel = CreateObject("Excel.Application") 'If Err < 0 Then 'MsgBox "Could not load Excel.", vbExclamation 'End 'End If End If On Error GoTo 0 excel.Visible = True mysheet = excel.ActiveWorkbook.ActiveSheet.Name Set excelsheet = excel.ActiveWorkbook.Sheets(mysheet) Set rng = excel.Application.InputBox(Prompt:="Select range", Type:=8) begrow = rng(1).Row --------------- Excess code cut ----------- |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel Opens but no worksheet | Excel Discussion (Misc queries) | |||
Inserting .dwg file in excel opens the drawing in autocad... | Excel Worksheet Functions | |||
How do I copy an entire worksheet to another instance of excel? | Excel Programming | |||
Excel opens without a visible worksheet | Excel Programming | |||
Excel ADO connection opens read-only instance of opened Excel | Excel Programming |