Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6578733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:48:31+00:00 2026-05-25T15:48:31+00:00

I have create an xla (excel add-in) that have a function to protect the

  • 0

I have create an xla (excel add-in) that have a function to protect the document (so that user could protect the document without knowing the password). This xla is added in every excel file that need this functionality.

when the xla is installed or added to excel, the protect button will be added in last menu. but when i click the button, an error occur show that

“Cannot run the macro Pivot Add-In 0.2′!protectSheet'”. The macro may not be available in this workbook or all macros may be disabled.”

The code that event handler onclicked is protectSheet, please see the source below:

Could anyone pointed my why this problem occur?

on ThisWorkbook

'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

On module1

Public Const TOOLBARNAME = "PivotTools"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:48:31+00:00Added an answer on May 25, 2026 at 3:48 pm

    After moving all function to module1 , then retain caller function on ThisWorkbook the error now gone. Seem that i have to define all functionality that call/ use constant (Public Const TOOLBARNAME = “PivotTools”) in the same file (in my case in module1)

    on module1 file

    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
    

    on ThisWorkbook

    '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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create an Excel Add-In. In that add-in are some modules and let's
I have create object lik e this testObj.prototype = { cVar: 15, init: function(c){
I have create CouchDB database with documents that have slash (/) in the document
I have create my own NSOpenGLView class, right now the data that i want
I have create name range on sheet A so I need to use this
This is what I currently have: CREATE OR REPLACE TRIGGER MYTRIGGER AFTER INSERT ON
I've read this book section about git branches. I have create a branch called
I have to create a site definition for a client that must contain pre-defined
I have to create the sin function from scratch in my Comp Sci class,
I have create a class MyConnection that extends NSURLConnection. I have implemented some delegate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.