Hallo,
Ik probeer een commandbar te maken en dat lijkt te lukken maar krijg deze niet aangeroepen met een cmd knop, ik ben nog steeds een beetje een leek op excel VBA en een commandbar is helemaal nieuw en kan er helaas weinig over vinden op het net, voor zover ik begrijp moet je een commandbar in een klasse module bouwen en gaat het oproepen van de sub anders dan in een form of module, ik heb dezelfde commandbar ook in een norm. module gezet maar dan de variable's zonder event's en dan lukt het oproepen wel maar dan werken de buttons zelf niet, en in de klasse module krijg ik een variable niet gedefineerd maar welke?
Dus nou twijfel ik of het nu in een normale of een klasse module moet? Googlen levert niets op en wat ik vind krijg ik ook niet aan de praat met dezelfde variable fout dus wat doe ik nou verkeerd?
Hieronder de code en het gaat om menubestand, hoe roep ik die aan?
Option Explicit
Public WithEvents Opslaan As CommandBarButton
Public WithEvents OpslAls As CommandBarButton
Public WithEvents Opvul1 As CommandBarButton
Public WithEvents Export As CommandBarButton
Public WithEvents Import As CommandBarButton
Public WithEvents Opvul2 As CommandBarButton
Public WithEvents Printer As CommandBarButton
Public WithEvents Opvul3 As CommandBarButton
Public WithEvents Afsluiten As CommandBarButton
Public DateString As String
Public FolderName As String
Public wsExp As Worksheet
Public Map As String
Function MenuBestand()
Public oCmbar As CommandBar
Set oCmbar = Application.CommandBars.Add(Position:=msoBarPopup, temporary:=True)
Set Opslaan = oCmbar.Controls.Add(msoControlButton)
Set OpslAls = oCmbar.Controls.Add(msoControlButton)
Set Opvul1 = oCmbar.Controls.Add(msoControlButton)
Set Export = oCmbar.Controls.Add(msoControlButton)
Set Import = oCmbar.Controls.Add(msoControlButton)
Set Opvul2 = oCmbar.Controls.Add(msoControlButton)
Set Printer = oCmbar.Controls.Add(msoControlButton)
Set Opvul3 = oCmbar.Controls.Add(msoControlButton)
Set Afsluiten = oCmbar.Controls.Add(msoControlButton)
With Opslaan
.Style = msoButtonIconAndCaption
.Height = 30
.Width = 120
.FaceId = 19
.Caption = "Opslaan"
End With
With OpslAls
.Style = msoButtonIconAndCaption
.Height = 30
.Width = 120
.FaceId = 21
.Caption = "Opsl. Als"
End With
With Opvul1
.Height = 15
.Width = 120
End With
With Export
.Style = msoButtonIconAndCaption
.Height = 30
.Width = 120
.FaceId = 22
.Caption = "Export"
End With
With Import
.Style = msoButtonIconAndCaption
.Height = 30
.Width = 120
.FaceId = 39
.Caption = "Import"
End With
With Opvul2
.Style = msoButtonIcon
.Height = 15
.Width = 120
End With
With Printer
.Style = msoButtonIconAndCaption
.Height = 30
.Width = 120
.FaceId = 22
.Caption = "Printer"
End With
With Opvul3
.Style = msoButtonIcon
.Height = 15
.Width = 120
End With
With Afsluiten
.Style = msoButtonIconAndCaption
.Height = 30
.Width = 120
.FaceId = 22
.Caption = "Afsluiten"
End With
oCmbar.ShowPopup (20), (60)
oCmbar.Delete
End Function
Private Sub Opslaan_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
ProgOpslaan
End Sub
Private Sub OpslALs_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
ProgOpslAls
End Sub
Private Sub Export_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
BestandExport
End Sub
Private Sub Import_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
End Sub
Sub ProgOpslaan(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
Application.ThisWorkbook.Save
End Sub
Sub ProgOpslAls(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
Map = Application.ThisWorkbook.Path
Application.Dialogs(xlDialogSaveAs).Show (Map)
End Sub
Sub BestandExport(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
'Updateby20200806
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim xWs As Worksheet
Dim xWb As Workbook
Dim xNWb As Workbook
Dim xFile As String
Application.ScreenUpdating = False
Set xWb = Application.ThisWorkbook
DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = xWb.Path & "\" & "export" & "\" & xWb.Name & wsExp.Name & " " & DateString
FileExtStr = ".xlsb": FileFormatNum = 50
MkDir FolderName
wsExp.Select
wsExp.Copy
xFile = FolderName & "\" & wsExp.Name & FileExtStr
Set xNWb = Application.Workbooks.Item(Application.Workbooks.Count)
xNWb.SaveAs xFile, FileFormat:=FileFormatNum
xNWb.Close False, xFile
Application.ScreenUpdating = True
End Sub