Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'main function'
- Public Sub protectSheet()
- ActiveWorkbook.ActiveSheet.protect Password:="password", AllowUsingPivotTables:=True
- End Sub
- Public Sub ShowToolbar()
- ' Assumes toolbar not already loaded '
- Application.CommandBars.Add Module1.TOOLBARNAME
- AddButton "Proteksi Sheet", "Memproteksi Pivot", 3817, "protectSheet"
- ' call AddButton more times for more buttons '
- With Application.CommandBars(Module1.TOOLBARNAME)
- .Visible = True
- .Position = msoBarTop
- End With
- End Sub
- Public Sub AddButton(caption As String, tooltip As String, faceId As Long, methodName As String)
- Dim Btn As CommandBarButton
- Set Btn = Application.CommandBars(Module1.TOOLBARNAME).Controls.Add
- With Btn
- .Style = msoButtonIcon
- .faceId = faceId ' choose from a world of possible images in Excel: see http://www.ozgrid.com/forum/showthread.php?t=39992 '
- .OnAction = methodName
- .TooltipText = tooltip
- End With
- End Sub
- Public Sub DeleteCommandBar()
- Application.CommandBars(TOOLBARNAME).Delete
- End Sub
- 'called when add-in installed
- Private Sub Workbook_AddinInstall()
- Call ShowToolbar
- End Sub
- 'called when add-in uninstalled
- Private Sub Workbook_AddinUninstall()
- Call DeleteCommandBar
- End Sub
- Public Const TOOLBARNAME = "PivotTools"
- Public Const TOOLBARNAME = "PivotTools"
- 'caller method'
- Public Sub protectDoc()
- On Error GoTo errorInfo
- protectSheet
- 'if success, show msg box'
- MsgBox ("Report berhasil diproteksi")
- Exit Sub
- errorInfo:
- MsgBox Err.Description & vbCrLf & Err.Number
- End Sub
- Public Sub protectSheet()
- ActiveWorkbook.ActiveSheet.protect Password:="password", AllowUsingPivotTables:=True
- End Sub
- Public Sub refreshDoc()
- On Error GoTo errorInfo
- refreshConnection
- protectSheet
- 'if success, show msg box'
- MsgBox ("Report berhasil diperbaharui")
- Exit Sub
- errorInfo:
- MsgBox Err.Description & vbCrLf & Err.Number
- End Sub
- Private Sub refreshConnection()
- ActiveWorkbook.ActiveSheet.Unprotect Password:="password"
- ActiveWorkbook.RefreshAll
- End Sub
- Public Sub ShowToolbar()
- ' Assumes toolbar not already loaded '
- Application.CommandBars.Add TOOLBARNAME
- AddButton "Proteksi Sheet", "Memproteksi Pivot", 225, "protectDoc"
- AddButton "Refresh Data", "Refresh Pivot", 459, "refreshDoc"
- ' call AddButton more times for more buttons '
- With Application.CommandBars(TOOLBARNAME)
- .Visible = True
- .Position = msoBarTop
- End With
- End Sub
- Public Sub AddButton(caption As String, tooltip As String, faceId As Long, methodName As String)
- Dim Btn As CommandBarButton
- Set Btn = Application.CommandBars(TOOLBARNAME).Controls.Add
- With Btn
- .Style = msoButtonIcon
- .faceId = faceId
- ' choose from a world of possible images in Excel: see http://www.ozgrid.com/forum/showthread.php?t=39992 '
- .OnAction = methodName
- .TooltipText = tooltip
- End With
- End Sub
- Public Sub DeleteCommandBar()
- Application.CommandBars(TOOLBARNAME).Delete
- End Sub
- 'called when add-in installed
- Private Sub Workbook_AddinInstall()
- Call Module1.ShowToolbar
- End Sub
- 'called when add-in uninstalled
- Private Sub Workbook_AddinUninstall()
- Call Module1.DeleteCommandBar
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement