Re: Force Consecutive Open for Multi-Selected Files OR Detect Multiple Files Opening
Quote from Andy PopeDisplay MoreNot sure how easily this approach would be to build into your system, especially as it requires a rethink on the code within the template file.
Rather than firing the addin routine and using the activeworkbook object pass the workbook object as an argument.
Template file Open event[vba]Private Sub Workbook_Open()
Application.Run "Main.xls!Opening", Me
End Sub[/vba]Addin routine[vba]Public Sub Opening(Book As Workbook)
MsgBox "Opening workbook " & Book.Name
End Sub[/vba]
In my test when opening 3 workbooks at once all 3 are opened when the addin routine is executed for the first time. You could check for all open workbooks and store information about whether the workbook has been processed or not.
Thanks Andy. Yes, I have given thought to both these suggestions but thought I might troll for some alternatives, particularly if Excel/VBA could detect whether it was being asked to open a single file or multiple files.
I have left the project open on these files so that I can add/revise code programatically (there is minimal programming within each workbook). I've been following the threads re adding VBA code programmatically but have been avoiding trying it. So changes to each workbooks Workbook_Open event would require that I change the code programmatically. I'll play with this suggestion to see if it works but I would still need to loop through the open files the first time to ensure the change has been made.
My easiest solution will be to modify the code in the add-in to loop through the open workbooks (and I need it anyway if your first suggestion works). Fortunately, each revision has a check built-in that can be used to determine if the workbook has been processed to ensure that the code isn't run again when the workbook is opened after successful updating and the files are unique enough that I can have the loop skip workbooks that aren't based on my template.
Not sure if anyone has any other suggestions but I think I'll use these. Still if anyone knows if Excel/VBA can detect multiple files being opened I would be interested to know how.
Thanks all!