Hallo, everybody.
This problem is due to a quite unusual situation, and I think there are little chances to replicate easily.
Anyway, I hope someone could understand it, and suggest me a way to work in.
I have a worksheet where I transfer information from an outer source using an addin that is saved in the ususal folder C:\Users\[user]\AppData\Roaming\Microsoft\AddIns.
The addin creare a form with a button added in the toolbar with this code:
Then, the ShowHideForm macro let the form visible, with the normal code:
Button and text boxes in the form works fine.
Everything is OK; but in these days I had to insert a new format for the aforesaid worksheet, so I had to write more code to differenziate some macro acted by the form buttons.
Morevoer, I had to insert a global variable to undersand which worksheet is open.
At the end, if I open only a workbook also with sheets of the 2 types, everything continues to works fine, but if I open 2 workbooks, the code no longer works, because when the UserForm1.Show command is implemented, the form always moves to the first open workbook, and never appears in the second, even by closing the first workbook (and closing the form itself, then it does not reopen).
Therefore, I cannot manage the addin with 2 workbooks open at the same time.
I thought about indicating to the form which is the active workbook, but I don't know how to do it, and then, even in that case, would the form's command macros act on the active workbook itself?
Is there someone that have a solution?
Thanks in advance.
This problem is due to a quite unusual situation, and I think there are little chances to replicate easily.
Anyway, I hope someone could understand it, and suggest me a way to work in.
I have a worksheet where I transfer information from an outer source using an addin that is saved in the ususal folder C:\Users\[user]\AppData\Roaming\Microsoft\AddIns.
The addin creare a form with a button added in the toolbar with this code:
VBA Code:
Set IlToolbar = Application.CommandBars.Add(Name:="ImmerLab", Position:=msoBarFloating, MenuBar:=False, Temporary:=True)
Set Button1 = IlToolbar.Controls.Add(Type:=msoControlButton)
With Button1
.BeginGroup = True
.Style = MsoButtonStyle.msoButtonIconAndCaptionBelow
.Caption = "Show/Hide"
.FaceId = 256
.OnAction = "ShowHideForm"
End With
IlToolbar.Protection = MsoBarProtection.msoBarNoCustomize + MsoBarProtection.msoBarNoMove
IlToolbar.Visible = True
Then, the ShowHideForm macro let the form visible, with the normal code:
VBA Code:
UserForm1.Show
Everything is OK; but in these days I had to insert a new format for the aforesaid worksheet, so I had to write more code to differenziate some macro acted by the form buttons.
Morevoer, I had to insert a global variable to undersand which worksheet is open.
At the end, if I open only a workbook also with sheets of the 2 types, everything continues to works fine, but if I open 2 workbooks, the code no longer works, because when the UserForm1.Show command is implemented, the form always moves to the first open workbook, and never appears in the second, even by closing the first workbook (and closing the form itself, then it does not reopen).
Therefore, I cannot manage the addin with 2 workbooks open at the same time.
I thought about indicating to the form which is the active workbook, but I don't know how to do it, and then, even in that case, would the form's command macros act on the active workbook itself?
Is there someone that have a solution?
Thanks in advance.