I have a VBA macro that opens by asking the user a series of questions (asking them to say which of the open workbooks performs which function). I have a series of userform.show commands as below:
UserForm2.Show ' select cost data file
Set piersBook = ActiveWorkbook
UserForm5.Show ' select IRR file
Set irrBook = ActiveWorkbook
UserForm6.Show ' select BC summary file
Set bcSummary = ActiveWorkbook
(now, after the event, I realise it would have been more simple to put these into one userform).
The net effect is for the last one not to display.
After some research I changed the code to:
UserForm2.Show ' select cost data file
Set piersBook = ActiveWorkbook
UserForm5.Show ' select IRR file
Set irrBook = ActiveWorkbook
DoEvents
UserForm6.Show ' select BC summary file
Set bcSummary = ActiveWorkbook
This worked for about 5 or 6 iterations, before it reverted to the original problem.
I put breakpoints in the userform initialize code. They were all called and the userforms all worked (until I removed the breakpoints again).
Finally I started removing the offending userform: the problem transfered itself to the next one back. And again, when that was removed, to the one before.
The userforms' code is identical:
Private Sub ListBox1_Click()
Workbooks(ListBox1.Value).Activate
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim wb As Workbook
For Each wb In Workbooks
ListBox1.AddItem wb.Name
Next wb
End Sub
Any thoughts? At the moment I am hardcoding the inputs which is not ideal. Many thanks.