通过单词机密性禁用宏

时间:2017-09-18 19:22:47

标签: ms-word word-vba

我试图创建一个宏,PopUp包含一个特定动作按钮的工具栏,但代码工作正常,我测试了每一行,但是当我从单词PoPUP中运行一条消息并阻止我运行它我不知道为什么 PS:我尝试了谷歌和论坛的每一个解决方案 我正在使用Word 2016和word 2007 这是我的代码

 Sub AddNewMB()
 Dim myCommandBar As CommandBar, myCommandBarCtl As CommandBarControl
 Dim myCommandBarSubCtl As CommandBarControl

 On Error GoTo AddNewMB_Err

 Set myCommandBar = CommandBars.Add(Name:="Airbus", Position:=msoBarTop, 
 menuBar:=True, Temporary:=False)
 myCommandBar.Visible = True
 myCommandBar.Protection = msoBarNoMove

Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlButton)
With myCommandBarCtl
  .BeginGroup = True
  .Caption = "UnGroup Shapes"
  .Style = msoButtonCaption
  .OnAction = "=UnGroupShapes_click()"
 End With

 Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlButton)
 With myCommandBarCtl
  .BeginGroup = True
  .Caption = "Group Shapes"
  .Style = msoButtonCaption
  .OnAction = "=GroupShapes_click()"
 End With

 Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlButton)
 With myCommandBarCtl
  .BeginGroup = True
  .Caption = "&Set Visibility Off"
  .Style = msoButtonCaption
  .OnAction = "=SampleMenuDisable()"
 End With

 Exit Sub

 AddNewMB_Err:
 Debug.Print Err.Number & vbCr & Err.Description
 Exit Sub
 End Sub
 Function GroupShapes_click()
 Dim MyMenu As CommandBar
 Dim myCommandBarClickMe As CommandBarControl
 Dim mydocument As Document
 Set mydocument = ActiveDocument
 On Error Resume Next

 ActiveDocument.Unprotect   'enregistré manuellement
 Dim S As Shape, t As Shape

 On Error GoTo GroupShapes_click_Err

 Set MyMenu = CommandBars("Airbus")
 Set myCommandBarClickMe = MyMenu.Controls(2)

 With CommandBars.ActionControl

 End With


 GroupShapes_click_Err:
 Debug.Print Err.Number & vbCr & Err.Description

 End Function


  Function SampleMenuDisable()
  Application.CommandBars("Sample Menu Bar").Visible = False
  Application.CommandBars("Menu Bar").Visible = True
  End Function

我想要的是防止这种情况发生在我使用的每个代码上,并为我使用的每个字安装此工具栏

这是我的错误error

我需要一些帮助我被困在这里 提前谢谢

1 个答案:

答案 0 :(得分:0)

  1. 将您的宏与导致您麻烦的问题分开。您尚未确定您发布的代码与您收到的错误消息有关。获取一个新文档并将以下代码添加到其中。

    Private Sub Test()
        MsgBox "This code is running."
    End Sub
    
  2. 将文档保存为启用宏。尝试运行代码。如果它运行,请关闭文档,退出Word。重新启动Word,加载文档,尝试再次运行代码。 如果代码在这些场景中的一个或两个中运行,则错误必须与包含您在上面发布的代码或代码本身的文档一起。在此处发布您上述测试的结果,我们可以在那里查找错误。

    1. 转到文件 - >选项 - >信托中心 - >信任中心设置。 选择“宏设置”'在左边。你会看到许多单选按钮。选择表示"启用所有宏(不推荐;可能运行危险代码)"的那个。根据您的描述,这是您的问题的责任设置。如果对此设置的审核无法解决您的问题,请发布此设置对话框的屏幕截图。