I worked out a solution that works perfectly by using a multidimensional array.
The code is:
Code:
Dim excelApp As Excel.Application
Dim wbk As Workbook
Dim sht As Worksheet
Private Sub cmdListBlocks_Click()
Dim Block As AcadBlock
Dim i As Integer
Dim MyBlockArray() As Variant
i = 0
For Each Block In ThisDrawing.Blocks
i = i + 1
ReDim Preserve MyBlockArray(2, i)
MyBlockArray(0, i) = Block.Name
MyBlockArray(1, i) = Block.Count
Next Block
Me.ListBoxBlocks.ColumnCount = 2
Me.ListBoxBlocks.ColumnWidths = "36;36"
Me.ListBoxBlocks.Column() = MyBlockArray
End Sub
Private Sub CommandButton1_Click()
Dim i As Integer
ListCount = Me.ListBoxBlocks.ListCount
On Error Resume Next
Set excelApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Err.Clear
Set excelApp = CreateObject("Excel.Application")
If Err <> 0 Then
MsgBox "Εrror Opening Excel!", vbExclamation
End
End If
End If
excelApp.Visible = True
Set wkbkObj = excelApp.Workbooks.Open(FileName:="c:\dipola.xls") ' here i just open a certain excel Workbook
Set sheetObj = wkbkObj.Worksheet(1) ' I put the values in the 2nd sheet
For i = 0 To ListCount - 1
If ListBoxBlocks.List(i, 0) = "C1" Then Range("B1").Cells.Value = ListBoxBlocks.List(i, 1)
If ListBoxBlocks.List(i, 0) = "C2" Then Range("B2").Cells.Value = ListBoxBlocks.List(i, 1) ' Here I make a lot of checks so i just wrote two to show the way I send values to certain cells in excel
Next
wkbkObj.Sheets("DIPOLA").Select ' I focus on the 1st sheet that is the actual report page for the user to print
End Sub
Private Sub CommandButton2_Click()
End
End Sub
I just created a UserForm with 3 buttons and a listbox (just to read the values from and send them to excel).
I'm not sure that it will work in 2011 LT but in 2009 and 2007 it does.
Bookmarks