Getting point data from Excel

Getting point data from Excel

Anonymous
Not applicable
401 Views
2 Replies
Message 1 of 3

Getting point data from Excel

Anonymous
Not applicable
I want to set startX, startY, startZ values (and other properties) for a spline from a table in Excel. Once I get that up and running I want to point the Excel cells to MathCAD formulas.

Am I in the right group? Anybody know how to do this?
0 Likes
402 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
wrote in message news:6032578@discussion.autodesk.com...
I want to set startX, startY, startZ values (and other properties) for a
spline from a table in Excel. Once I get that up and running I want to point
the Excel cells to MathCAD formulas.

Am I in the right group?

If you're wanting to use vba to automate autocad you are.

this isn't a Mathcad (whatever that is?) group so don't know if you'll find
a lot of help on that part.

Anybody know how to do this?

have you googled the archives on connecting excel to autocad yet? there's
lots of info avail for the basics, creating the reference to excel, reading
and writing to cells etc....

you haven't indicated what parts you already know how to do or what you have
as a starting point.
0 Likes
Message 3 of 3

Anonymous
Not applicable
the following is some simple, slow, and not terribly bright code, that will work a decent amount of time, will get you started quickly. To do it "right" will cause more questions and problems right now, you can "grow" into the better ways later.

The second routine does all the work. pass it the name of your workbook, the name of your worksheet, and the starting and ending cols.rows.

It prints the results in the debug window.

'-------------- snip--------------------

Sub Main()

Dim retValues As Variant


Dim I As Long, J As Long
' Sample data:
' Open a Workbook called "c:\book1.xls"
' Read from a worksheet called "Sheet1"
' Start Reading At Row 1, Column 2
' End Reading at Row 8, Column 11



retValues = ReadWorkSheetData("c:\book1.xls", "Sheet1", 1, 2, 8, 11)

' Build a string to output data
If IsEmpty(retValues) Then
MsgBox "Problem reading your data: check Debug window"
Exit Sub
End If

' Dump data to Debug.window
For I = 0 To UBound(retValues, 1)
For J = 0 To UBound(retValues, 2)
Debug.Print retValues(I, J),
Next J
Debug.Print
Next I

MsgBox "The Values read from Excel are printed in your debug window"





End Sub

Function ReadWorkSheetData(Filename As String, WorkSheet As String, StartRow As Long, StartCol As Long, EndRow As Long, EndCol As Long)
' reads data out from an excel spreadsheet and returns it as a variant safearray

Dim retValues() As Variant ' returns data in an array of safearrays
Dim I As Long, J As Long
Dim tmpVnt As Variant



Dim NumCols As Long, NumRows As Long

NumCols = EndCol - StartCol + 1: NumRows = EndRow - StartRow + 1
' resize the array on the fly
ReDim retValues(NumRows - 1, NumCols - 1)

' Start Excel
Dim xl As Object, wb As Object, ws As Object
'start excel
Set xl = CreateObject("Excel.application")
If xl Is Nothing Then Debug.Print "Cannot Open Excel": Exit Function

' open the workbook
Set wb = xl.Workbooks.Open(Filename, True, True)
If wb Is Nothing Then Debug.Print "Cannot open WorkBook " & Filename: Exit Function

' look for the worksheet
Set ws = wb.Worksheets.Item(WorkSheet)
If ws Is Nothing Then Debug.Print "Cannot Locate Worksheet " & WorkSheet: Exit Function

' Start Reading the data
For I = 0 To (NumRows - 1)
For J = 0 To (NumCols - 1)
retValues(I, J) = ws.Cells(StartRow + I, StartCol + J).Value
Next J
Debug.Print
Next I

' clean up before we leave
wb.Close (False): Set ws = Nothing: Set wb = Nothing
xl.Quit: Set xl = Nothing

ReadWorkSheetData = retValues


End Function


'----------------- snip--------------------
0 Likes