Capturing multiple range in Excel from AutoCAD VBA

Capturing multiple range in Excel from AutoCAD VBA

Anonymous
Not applicable
361 Views
1 Reply
Message 1 of 2

Capturing multiple range in Excel from AutoCAD VBA

Anonymous
Not applicable
I have a project I am working on which in AutoCAD VBA which needs to read in
the information contained in a multiple range. The following is my code:

Set ExcelApp = GetObject(, "Excel.Application")

If Err Then
Err.Clear
Set ExcelApp = CreateObject("Excel.Application")
If Err Then
MsgBox Err.Description, vbCritical, "Warning"
Exit Function
End If
End If

On Error GoTo 0

Set ExcelWorkbook = ExcelApp.Workbooks.Open(Temp)

Set ExcelWorkbook = ExcelApp.ActiveWorkbook

rangeArray = ExcelWorkbook.worksheets("Output").Range("F37:F60")

ExcelApp.Application.Quit

The above code works fine capturing the values of the range F37:F60. I need
the range F37:F60 plus the cells F10 and B3 in the same array. I can create
a named range in the spreadsheet called Range1 that is defined as
=Output!$F$37:$F$60,!Output$F$10,!Output$B$3. I have attempted the
following code based on examples in the Excel VBA help file, but neither of
them work:

rangeArray = ExcelWorkbook.worksheets("Output").Range("F37:F60,F10,B3")

rangeArray = ExcelWorkbook.worksheets("Output").Range("Range1") 'Range1
defined as above

Each of the above lines only returns the range F37:F60.

Any help or suggestions at all would be very much appreciated. TIA

Michael Teague
CADD Support Technician
Matrix Service, Inc.
0 Likes
362 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Hi! Michael,

I dont know why it doesn't work in your case.
I have the following code which essentially does the same thing and it works
fine in A2K.
Could remove "On Error go to 0 and check what trap the error(if at all error
is generated)?

'______________________________
Sub f_selectRange()
Dim po_xl As Application
Dim po_ws As Worksheet
Dim po_rg As Range

'keep the excel open to run this
Set po_xl = GetObject(, "Excel.Application")

'select multiple cells
Set po_ws = po_xl.Worksheets("Sheet2")
po_ws.Activate
Set po_rg = po_ws.Range("A1:A10,F1:F3,B10")
po_rg.Select
End Sub
'______________________________

--
bye,

P.Murali
Michael Teague wrote in message
news:81gt4p$8sb6@adesknews2.autodesk.com...
> I have a project I am working on which in AutoCAD VBA which needs to read
in
> the information contained in a multiple range. The following is my code:
>
> Set ExcelApp = GetObject(, "Excel.Application")
>

> Michael Teague
> CADD Support Technician
> Matrix Service, Inc.
>
>
0 Likes