宏被单词机密性禁用 [英] Macro is disabled by word confidentiality
问题描述
我正在尝试创建一个宏,该宏会弹出一个包含用于特定操作的按钮的工具栏,但是代码可以正常工作,并且我测试了每一行,但是当我运行它时,出现了来自单词PoPUP的消息并阻止我运行此消息,不要为什么
PS:我尝试了Google和论坛中的所有Signle解决方案
我正在使用Word 2016和Word 2007
这是我的代码
I'm trying to create a macro that PopUp a toolBar containing button for a specific action but the code works fine and I tested every single line but when I run it a message from word PoPUP and prevent me to run this and I donno why
PS : I tried every signle solution in Google and forums
and I'm working with Word 2016 and word 2007
this is My code
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
我想要的是防止这种情况发生在我使用的每个代码上,并为我使用的每个单词安装此工具栏
What I want is to prevent this to happen to every code I use and install this toolBar for everyword I use
这是我的错误
我需要一些帮助,我被困在这里 提前谢谢
I need some help I'm stuck here thank's in advance
推荐答案
-
将宏与引起麻烦的问题分开.您尚未确定发布的代码与收到的错误消息有关.制作一个新文档,并在其中添加以下代码.
Separate your macro from the issue that gives you trouble. You haven't established that the code you published is related to the error message you receive. Take a new document and add the following code to it.
Private Sub Test()
MsgBox "This code is running."
End Sub
将文档另存为启用宏.尝试运行代码.如果运行,请关闭文档,然后退出Word.重新启动Word,加载文档,然后尝试再次运行代码. 如果代码在这两种情况中的一种或两种中都运行,则故障必须出在包含您上面发布的代码的文档中,或者是代码本身.在此处发布上述测试的结果,我们可以在此处查找错误.
Save the document as macro enabled. Try to run the code. If it runs, close the document, quit Word. Restart Word, load the document, try to run the code again. If the code runs in one or both of these scenarios the fault must be with the document that contains the code you posted above or with the code itself. Post the result of your above test here and we can look for the error there.
- 转到文件"->选项"->信任中心"->信任中心设置". 选择左侧的宏设置".您将看到许多单选按钮.选择一个说启用所有宏(不建议使用;可能运行潜在危险的代码)"的代码.根据您的描述,这是应为您的问题负责的设置.如果对此设置进行审核仍不能解决您的问题,请发布此设置对话框的屏幕截图.
- Go to File -> Options -> Trust Center -> Trust Center Settings. Select 'Macro Settings' on the left. You will see a number of radio buttons. Select the one which says "Enable all macros (not recommended; potentially dangerous code can run)". From your description, this is the setting to blame for your problem. If the review of this setting doesn't solve your problem please post a screenshot of this setting dialog box.
这篇关于宏被单词机密性禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!