我已经构建了一个 Word 启用宏的模板 (.dotm),当我将它保存到我的 Word 启动文件夹时,它可以在我的机器上完美运行。但是,当我将.dotm
文件发送给我的同事(有些与我在相同的环境中,有些不是)时,按下自定义 ui 功能区按钮时会生成错误:
由于您的安全设置,该宏无法找到或已被禁用
宏设置设置为运行所有宏,包含模板的文件夹>是受信任的位置
....更多帮助选项如下
我的同事还将文件保存到他们的启动文件夹并加载 Word。功能区显示完美,但宏不运行。我和我的同事在网上进行了大量搜索,但无法找出问题所在,因为我的所有配置都是正确的,据我所知,我将在下面列出:
- 宏设置:启用所有宏
- 检查对 VBA 项目对象模型的信任访问
- 启动文件夹被建立为受信任的位置
自定义 UI XML
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon>
<tabs>
<tab id="customTab" label="WebMerge">
<group id="CustomHelp" label="Map Tags">
<button id="mapper"
visible="true"
size="large"
label="Open Mapper"
screentip="Opens Mapping Engine"
onAction="LoadMappingGuide"
imageMso="FindDialog"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
标准模块中的 UI 功能区连接
Option Explicit
Sub LoadMappingGuide(ByVal Control As IRibbonControl) 'also tried without ByVal
'select business unit or automatically detect based on username against our database ...
Dim mappingForm As New mappingGuide
mappingForm.Show vbModal
End Sub
mappingForm(用户窗体)代码
Option Explicit
Private Sub cancelButton_Click()
Unload Me
End Sub
Private Sub searchBox_Change()
generateList
Dim n As Long, index As Long
index = 0
For n = 0 To smartTagList.ListCount - 1
If InStr(1, smartTagList.List(index, 0), searchBox.Value, vbTextCompare) > 0 Then
index = index + 1
ElseIf InStr(1, smartTagList.List(index, 1), searchBox.Value, vbTextCompare) > 0 Then
index = index + 1
ElseIf InStr(1, smartTagList.List(index, 2), searchBox.Value, vbTextCompare) > 0 Then
index = index + 1
Else
smartTagList.RemoveItem (index)
End If
Next n
End Sub
Private Sub smartTagList_Click()
If smartTagList.ListIndex > -1 And smartTagList.Selected(smartTagList.ListIndex) Then
Dim smartyTag As String
smartyTag = smartTagList.List(smartTagList.ListIndex, 2)
Selection.Range.Text = smartyTag
End If
Unload Me
End Sub
Private Sub UserForm_Initialize()
generateList
End Sub
Private Sub generateList()
'replace with code to get values from database
Dim fields() As String
Dim descriptions() As String
Dim smartyTags() As String
fields = Split("Producer Name,Producer Address,Producer City,Producer State,Producer Zip,Insured Name,Insured Address,Insured City,Insured State,Insured ZIp,Risk Premium,TRIA Premium,Final Premium", ",")
descriptions = Split("Name of Producer,Address Line of Producer,City of Producer,State of Producer,Zip Code of Producer,Name of Insured,Address of Insured,City of Insured,State of Insured,ZIp of Insured,Total Premium for all risks excluding terrorism taxes and surcharges.,Premium resulting from acceptance of terrorism protection,Total Premium of quote / policy", ",")
smartyTags = Split("{$Producer Name},{$ProducerAddress},{$ProducerCity},{$ProducerState},{$ProducerZip},{$InsuredName},{$InsuredAddress},{$InsuredCity},{$InsuredState},{$InsuredZIp},{$RiskPremium},{$TRIAPremium},{$FinalPremium}", ",")
Dim i As Long
For i = LBound(fields) To UBound(fields)
With smartTagList
.AddItem
.List(i, 0) = fields(i)
.List(i, 1) = descriptions(i)
.List(i, 2) = smartyTags(i)
End With
Next
End Sub
这就是我的 VBE 打开后的样子.dotm
。