J
John Coon
Ron,
I added the Set wkbObj = ExcelApp.ActiveWorkbook but it return a 0 for calc
in textbox1
The excel file only has two colnums A & B see below. When I subsitute a
hard path = Set wkbObj =
workbooks.Open(Filename:="c:\vba\sample\costing.xls")
the routines works fine. ? Why or how do I get this to read costing.xls
which will be the currently open and have it read the values in colnum A &
B.
I thought about adding a commonDialog to select the file but that seems like
overkill. if I could just connect to the currently open excel sheet i'd be
fine.
A B
duct 2.00
as-built 5.00
Thank you for your comments.
John coon
Private Sub CommandButton1_Click()
On Error Resume Next
Set ExcelApp = CreateObject("excel.Application")
If Err <> 0 Then
Err.Clear
MsgBox "Could not start Excel", vbExclamation
End
End If
ExcelApp.Visible = True
''''''Set wkbObj = workbooks.Open(Filename:="c:\vba\sample\costing.xls")
Set wkbObj = ExcelApp.ActiveWorkbook
Set shtObj = wkbObj.Worksheets("sheet1")
Dim i, j As Integer
Dim pnum, anum, atot As Double
Dim lnam, enam As String
Dim ent As Object
i = 1: anum1 = 0#: anum2 = 0#: atot = 0#:
lnam = shtObj.Cells(i, 1).Value
pnum = shtObj.Cells(i, 2).Value
Do While Not (lnam = "")
For j = 0 To ThisDrawing.ModelSpace.Count - 1
Set ent = ThisDrawing.ModelSpace.Item(j)
If ent.EntityType = 24 And ent.Layer = lnam Then
anum1 = ent.Area
anum2 = anum2 + anum1
End If
Next j
atot = atot + (anum2 * pnum)
anum1 = 0#: anum2 = 0#
i = i + 1
lnam = shtObj.Cells(i, 1).Value
pnum = shtObj.Cells(i, 2).Value
Loop
ExcelApp.Quit
TextBox1.Text = atot
End Sub
I added the Set wkbObj = ExcelApp.ActiveWorkbook but it return a 0 for calc
in textbox1
The excel file only has two colnums A & B see below. When I subsitute a
hard path = Set wkbObj =
workbooks.Open(Filename:="c:\vba\sample\costing.xls")
the routines works fine. ? Why or how do I get this to read costing.xls
which will be the currently open and have it read the values in colnum A &
B.
I thought about adding a commonDialog to select the file but that seems like
overkill. if I could just connect to the currently open excel sheet i'd be
fine.
A B
duct 2.00
as-built 5.00
Thank you for your comments.
John coon
Private Sub CommandButton1_Click()
On Error Resume Next
Set ExcelApp = CreateObject("excel.Application")
If Err <> 0 Then
Err.Clear
MsgBox "Could not start Excel", vbExclamation
End
End If
ExcelApp.Visible = True
''''''Set wkbObj = workbooks.Open(Filename:="c:\vba\sample\costing.xls")
Set wkbObj = ExcelApp.ActiveWorkbook
Set shtObj = wkbObj.Worksheets("sheet1")
Dim i, j As Integer
Dim pnum, anum, atot As Double
Dim lnam, enam As String
Dim ent As Object
i = 1: anum1 = 0#: anum2 = 0#: atot = 0#:
lnam = shtObj.Cells(i, 1).Value
pnum = shtObj.Cells(i, 2).Value
Do While Not (lnam = "")
For j = 0 To ThisDrawing.ModelSpace.Count - 1
Set ent = ThisDrawing.ModelSpace.Item(j)
If ent.EntityType = 24 And ent.Layer = lnam Then
anum1 = ent.Area
anum2 = anum2 + anum1
End If
Next j
atot = atot + (anum2 * pnum)
anum1 = 0#: anum2 = 0#
i = i + 1
lnam = shtObj.Cells(i, 1).Value
pnum = shtObj.Cells(i, 2).Value
Loop
ExcelApp.Quit
TextBox1.Text = atot
End Sub