I have some VBA code attached to a form which opens an Excel file, and extracts specific data within a spreadsheet. This data is then placed within a listbox. When executed, the code works great!
The problem I'm faced with is that I want to set this up within a report. However, when I try to place this code within the report's 'On Activate' event, I receive a Run-time error '2191' stating that I can't set the Row Source property after printing has started.
Here's the code in question. How can I assign the Row Source of a listbox (via VBA) prior to printing?
Dim ExApp As Excel.Application
With ExApp
.Workbooks.Open FileName:=strInputFileName
.Sheets("Info"
.Select
End With
zz = "Num;Rate;St;F4;F5;F6;F7;F8;F9;Notes"
For Each X In ExApp.Range("A21", ExApp.Range("A20"
.End(xlDown).Offset(1, 0))
X.Select
For Each y In ExApp.Range(ExApp.ActiveCell, ExApp.ActiveCell.Offset(0, 9))
If y <> ExApp.ActiveCell Then z = z & ";" & y Else z = y
Next y
If zz <> Empty Then zz = zz & ";" & z Else zz = z
z = Empty
Next X
LB_Utilization.RowSource = zz
zz = Empty -illini
The problem I'm faced with is that I want to set this up within a report. However, when I try to place this code within the report's 'On Activate' event, I receive a Run-time error '2191' stating that I can't set the Row Source property after printing has started.
Here's the code in question. How can I assign the Row Source of a listbox (via VBA) prior to printing?
Dim ExApp As Excel.Application
With ExApp
.Workbooks.Open FileName:=strInputFileName
.Sheets("Info"
End With
zz = "Num;Rate;St;F4;F5;F6;F7;F8;F9;Notes"
For Each X In ExApp.Range("A21", ExApp.Range("A20"
X.Select
For Each y In ExApp.Range(ExApp.ActiveCell, ExApp.ActiveCell.Offset(0, 9))
If y <> ExApp.ActiveCell Then z = z & ";" & y Else z = y
Next y
If zz <> Empty Then zz = zz & ";" & z Else zz = z
z = Empty
Next X
LB_Utilization.RowSource = zz
zz = Empty -illini