Message 1 of 5
not code error in vba, vba not read exce data

Not applicable
12-23-2006
01:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
it's believale thing happen
ever if vba code has not error, basic program did not read excel file
vba not read excel file and to run and to terminate
what is problem? who is know reason?
code following
data attached is vba code,and excel file
following is code
Dim xlapp As Excel.Application
Dim xlbook As Excel.Application
Dim xlsheet As Excel.worksheet
Dim xlrange As Excel.Range
Dim pointobj As AcadPoint
Dim location(0 To 2) As Long
Dim ra, dec As Double
Dim radegree As Double
Dim decdegree As Double
Dim dist As Double
Dim indx As Double
Dim jndx As Double
Dim lngrows As Double
Dim lngcols As Long
Dim mas As Long
Dim sign As String
Dim coeff As Integer
Dim cof As Integer
Dim radtrad As Long
Dim decdtrad As Long
MsgBox "be patience,works slowly"
On Error Resume Next
Err.Clear
Set xlapp = GetObject(, "excel.application")
Set xlapp = CreateObject("excel application")
Const pi = 3.141592
xlapp.Display.alerts = False
xlapp.Visible = True
xlapp.WindowState = xlMinimized
Set xlbook = xlapp.Workbooks.Open(FileName:="c:\200mas.xls")
xlsheet.Activate
'get excel data
lngrows = xlbook.activesheet.usedrange.Rows.Count
lngcols = xlbook.activesheet.usedrange.Columns.Count
AcadApplication.widowstate = acMax
Set xlsheet = xlbook.worksheet(1)
ReDim dataarr(lngrows - 1, lngcols - 1)
For indx = 1 To lngcols
For jndx = 11 To lngrows
dataarr(indx - 1, jndx) = xlsheet.Cells(indx, jndx):
dataarr(indx - 1, jndx + 1) = xlsheet.Cells(indx, jndx + 1):
dataarr(indx - 1, jndx + 2) = xlsheet.Cells(indx, jndx + 2):
ra = dataarr(indx, jndx)
dec = dataarr(indx, jndx + 1)
mas = dataarr(indx, jndx + 2)
If xlsheet.Cells(indx, jndx) = "ra" Then
indx = indx + 1
End If
sign = Left("dec", 1)
If sign = "-" Then
coeff = -1
Else
coeff = 1
End If
sign = Left(dec, 1)
If sign = "+" Then
cof = 1
End If
radegree = 15 * Val(Mid("ra", 1, 2)) + 15 * Val(Mid("ra", 4, 2)) / 60 + 15 *
Val(Mid("ra", 7, 6)) / 3600
decdegree = Val(Mid("dec", 2, 2)) * coeff * cof + Val(Mid("dec", 5, 2)) * coeff * cof /
60 + Val(Mid("dec", 8, 6)) * coeff * cof / 3600
'in hipparcos,distance display mas(mili-arcs-econd), so must do 1000/mas
dist = (1000 / Val(mas)) * 3.26 'dist is parsec 5*3.26 light year
radtrad = (radegree / 180) * pi 'ra transferring from degree to radian
decdtrad = (decdegree / 180) * pi 'dec tranfering from degree to radian
'cosmic 3-D point (x,y,z)- sine cosine is used
'modelspace command is dist
location(0) = dist * Cos(decdtrad) * Cos(radtrad): location(1) = dist * Sin(radtrad) *
Cos(decdtrad): location(2) = dist * Sin(decdtrad)
Set pointobj = ThisDrawing.ModelSpace.AddPoint(location)
Next
Next
ZoomAll
xlapp.DisplayAlerts = True
xlbook.Close savechanges:=False
xlapp.Quit
Set xlsheet = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
DoEvents
ever if vba code has not error, basic program did not read excel file
vba not read excel file and to run and to terminate
what is problem? who is know reason?
code following
data attached is vba code,and excel file
following is code
Dim xlapp As Excel.Application
Dim xlbook As Excel.Application
Dim xlsheet As Excel.worksheet
Dim xlrange As Excel.Range
Dim pointobj As AcadPoint
Dim location(0 To 2) As Long
Dim ra, dec As Double
Dim radegree As Double
Dim decdegree As Double
Dim dist As Double
Dim indx As Double
Dim jndx As Double
Dim lngrows As Double
Dim lngcols As Long
Dim mas As Long
Dim sign As String
Dim coeff As Integer
Dim cof As Integer
Dim radtrad As Long
Dim decdtrad As Long
MsgBox "be patience,works slowly"
On Error Resume Next
Err.Clear
Set xlapp = GetObject(, "excel.application")
Set xlapp = CreateObject("excel application")
Const pi = 3.141592
xlapp.Display.alerts = False
xlapp.Visible = True
xlapp.WindowState = xlMinimized
Set xlbook = xlapp.Workbooks.Open(FileName:="c:\200mas.xls")
xlsheet.Activate
'get excel data
lngrows = xlbook.activesheet.usedrange.Rows.Count
lngcols = xlbook.activesheet.usedrange.Columns.Count
AcadApplication.widowstate = acMax
Set xlsheet = xlbook.worksheet(1)
ReDim dataarr(lngrows - 1, lngcols - 1)
For indx = 1 To lngcols
For jndx = 11 To lngrows
dataarr(indx - 1, jndx) = xlsheet.Cells(indx, jndx):
dataarr(indx - 1, jndx + 1) = xlsheet.Cells(indx, jndx + 1):
dataarr(indx - 1, jndx + 2) = xlsheet.Cells(indx, jndx + 2):
ra = dataarr(indx, jndx)
dec = dataarr(indx, jndx + 1)
mas = dataarr(indx, jndx + 2)
If xlsheet.Cells(indx, jndx) = "ra" Then
indx = indx + 1
End If
sign = Left("dec", 1)
If sign = "-" Then
coeff = -1
Else
coeff = 1
End If
sign = Left(dec, 1)
If sign = "+" Then
cof = 1
End If
radegree = 15 * Val(Mid("ra", 1, 2)) + 15 * Val(Mid("ra", 4, 2)) / 60 + 15 *
Val(Mid("ra", 7, 6)) / 3600
decdegree = Val(Mid("dec", 2, 2)) * coeff * cof + Val(Mid("dec", 5, 2)) * coeff * cof /
60 + Val(Mid("dec", 8, 6)) * coeff * cof / 3600
'in hipparcos,distance display mas(mili-arcs-econd), so must do 1000/mas
dist = (1000 / Val(mas)) * 3.26 'dist is parsec 5*3.26 light year
radtrad = (radegree / 180) * pi 'ra transferring from degree to radian
decdtrad = (decdegree / 180) * pi 'dec tranfering from degree to radian
'cosmic 3-D point (x,y,z)- sine cosine is used
'modelspace command is dist
location(0) = dist * Cos(decdtrad) * Cos(radtrad): location(1) = dist * Sin(radtrad) *
Cos(decdtrad): location(2) = dist * Sin(decdtrad)
Set pointobj = ThisDrawing.ModelSpace.AddPoint(location)
Next
Next
ZoomAll
xlapp.DisplayAlerts = True
xlbook.Close savechanges:=False
xlapp.Quit
Set xlsheet = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
DoEvents