I have problem with hide my custom dialog frame. After pressing buttons (they have calls to other macros), I still have my dialog frame, how to hide it? I am working in "Dane_Makro" sheet. My previous version worked fine (i did not add 2 additional buttons, but i edited vbYesNo buttons - the scheme was very similar) Regards
'Public btnDlg As DialogSheet
Sub CallBots()
Dim btnDlg As DialogSheet
Dim ButtonDialog As String
ButtonDialog = "CustomButtons"
Dim klik As Boolean
klik = True
Dim oSHL As Object: Set oSHL = CreateObject("WScript.Shell")
Application.ScreenUpdating = False
Application.EnableEvents = False
On Error Resume Next
Application.DisplayAlerts = False
ActiveWorkbook.DialogSheets(ButtonDialog).Delete
Err.Clear
Application.DisplayAlerts = True
Set btnDlg = ActiveWorkbook.DialogSheets.Add
With btnDlg
.Name = ButtonDialog
.Visible = xlSheetHidden
With .DialogFrame
.Height = 70
.Width = 300
.Caption = "Generowanie plików do BOTÓW"
End With
.Buttons("Button 2").Visible = False
.Buttons("Button 3").Visible = False
.Labels.Add 100, 50, 100, 100
.Labels(1).Caption = "Jak utowrzyć pliki wsadowe do botów?"
.Buttons.Add 220, 44, 130, 18 'Custom Button #1,index #3
With .Buttons(3)
.Caption = "Nowe pliki wsadowe"
.OnAction = "MakeBotsNew"
End With
.Buttons.Add 220, 64, 130, 18 'Custom Button #2,index #4
With .Buttons(4)
.Caption = "Konsolidacja plików wsadowych"
.OnAction = "MakeBotsConso"
End With
If .Show = False Then
oSHL.PopUP "Anulowanie procesu", 1, "Tworzenie plików", vbInformation
klik = False
End If
End With
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'On Error Resume Next
DialogSheets("CustomButtons").Delete
Err.Clear
Application.DisplayAlerts = True
Application.ScreenUpdating = True
btnDlg.Visible = xlSheetVeryHidden
'Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
You're going to need to add an (optional?) argument to your MakeBotsNew
and MakeBotsConso
macros, like so:
Sub MakeBotsNew(Optional Name As String = "")
'Existing Code here
'After existing code:
If Len(Name) > 0 Then ThisWorkbook.DialogSheets(Name).Hide 'Hide dialog box
End Sub
Then, you need to add the ButtonDialog name as an argument to the .OnAction
, which also means wrapping it it single-quotes:
.OnAction = "'MakeBotsNew """ & ButtonDialog & """'"
(I still don't understand A) why you are creating your Dialog in code instead of doing it beforehand and B) why you are using a DialogSheet instead of a UserForm)
As a DialogSheet is a Sheet, you need to set the .Visible
property to xlSheetHidden
or xlSheetVeryHidden
Using .Hide
is for UserForms, which replaced DialogSheets back in... 2000?