我有一个excel工作簿,其中包含几百个选项卡,除非需要,否则这些选项卡都非常隐藏。我进行了设置,以便用户可以从主工作表中选择数据源,并将其传输到所需的特定工作表。然后,当他们完成任务后,他们将返回主页,并再次隐藏所有内容。我需要的是一种将命令按钮附加到功能区的方法,以便它始终存在并隐藏除主页之外的所有内容。
我曾经在每张纸上放了一个按钮,甚至尝试了一个留在角落里的浮动形状。虽然这些是答案,但我更愿意只是在功能区上贴一个按钮而忘记它。但是,如何在功能区中动态创建一个按钮,该按钮将随工作簿一起传输,以便任何计算机上的每个用户都可以使用该按钮?
答案 0 :(得分:0)
我通过为工作簿创建自定义选项卡和按钮找到了解决方法。它会在工作簿打开时创建选项卡,并在您关闭书籍时将其删除。
Private Sub Workbook_Activate()
Dim hFile As Long
Dim path As String, fileName As String, ribbonXML As String, user As String
hFile = FreeFile
user = Environ("Username")
path = "C:\Users\" & user & "\AppData\Local\Microsoft\Office\"
fileName = "Excel.officeUI"
ribbonXML = "<mso:customUI xmlns:mso='http://schemas.microsoft.com/office/2009/07/customui'>" & vbNewLine
ribbonXML = ribbonXML + " <mso:ribbon>" & vbNewLine
ribbonXML = ribbonXML + " <mso:qat/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:tabs>" & vbNewLine
ribbonXML = ribbonXML + " <mso:tab id='reportTab' label='Pats Tools' insertBeforeQ='mso:TabFormat'>" & vbNewLine
ribbonXML = ribbonXML + " <mso:group id='reportGroup1' label='Month' autoScale='true'>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Months1' label='Previous' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='AccessTableEvents' onAction='MonthPrevious.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Months2' label='Current' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='AccessListEvents' onAction='MonthCurrent.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Months3' label='Next' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='AccessTableEvents' onAction='MonthNext.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Months4' label='All' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='AccessTableEvents' onAction='AllMonths.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " </mso:group>" & vbNewLine
ribbonXML = ribbonXML + " <mso:group id='reportGroup2' label='Properties' autoScale='true'>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Properties1' label='All' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='BlogHomePage' onAction='AllProperties.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Properties2' label='Name1' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='BlogHomePage' onAction='Name1.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Properties3' label='Name2' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='BlogHomePage' onAction='Name2.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Properties4' label='Name3' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='BlogHomePage' onAction='Name3.ClearSheet'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Properties5' label='Name4' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='BlogHomePage' onAction='Name4.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='Properties6' label='Name5' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='BlogHomePage' onAction='Name5.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " </mso:group>" & vbNewLine
ribbonXML = ribbonXML + " <mso:group id='reportGroup4' label='Edit Task' autoScale='true'>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='ActionButton1' label='Type' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='BlogHomePage' onAction='AddTypemod.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='ActionButton2' label='Section' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='BlogHomePage' onAction='AddSectionMod.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='ActionButton3' label='Empty' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='BlogHomePage' onAction='CedarCreek.calling'/>" & vbNewLine
ribbonXML = ribbonXML + " </mso:group>" & vbNewLine
ribbonXML = ribbonXML + " </mso:tab>" & vbNewLine
ribbonXML = ribbonXML + " </mso:tabs>" & vbNewLine
ribbonXML = ribbonXML + " </mso:ribbon>" & vbNewLine
ribbonXML = ribbonXML + "</mso:customUI>"
ribbonXML = Replace(ribbonXML, """", "")
Open path & fileName For Output Access Write As hFile
Print #hFile, ribbonXML
Close hFile
End Sub