Excel 2010 中的自定义附加单元格操作

发布于 2024-12-07 02:06:33 字数 395 浏览 0 评论 0原文

我想通过添加更多“其他单元格操作”来扩展 MS Excel 2010。 (可通过单元格右键单击 > 其他单元格操作进行访问)。具体来说,我希望 Excel 能够:

  1. 通过以下操作将五到八位数字识别为部件号:“打开技术文档的 URL”
  2. 将字符串“OR ## #####”(# 表示数字)识别为订单参考操作:“打开规格文件”和“打开材料文件”(两个 Excel 文件都位于 Intranet 中的指定路径)

现在,我不知道如何对此进行编程。我怀疑需要一些 XML 片段,可能还需要一些 VB 代码。 VB 代码不会成为问题 - 我有宏来执行 Excel 2003 的功能 - 但我不知道将其放置在哪里。

请给我一些指示,我已经问过谷歌但无法得到答案,似乎“附加操作”是很常见的短语:)

I'd like to extend the MS Excel 2010 by adding some more "Additional Cell Actions". (accessible via cell right-click > Additional Cell Actions). Specifically, I'd like Excel to:

  1. recognize five-to-eight digit numbers as Part Numbers with action: "Open URL to technical docs"
  2. recognize string "OR ## #####" (# for digit) as Order Reference with actions: "Open spec file" and "Open material file" (both Excel files located at specified paths in the intranet)

Now, I have no idea how to program this. I suspect that some XML snippet is needed and probably some VB code too. VB code wouldn't be a problem - I have macros doing those functionalities done for Excel 2003 - but I have no idea where to place it.

Please give me some pointers, I've asked Google but can't get the answer, seems that "Additional Actions" is pretty common phrase :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏佲洛 2024-12-14 02:06:33

这可以通过向工作簿添加右键单击事件处理程序来实现

在工作簿模块中添加此代码

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    Dim cBut As CommandBarButton
    Dim v As Variant

    On Error Resume Next

    v = Target

    ' Remove any previously added menu items
    Application.CommandBars("Cell").Controls("Open URL to technical docs").Delete
    Application.CommandBars("Cell").Controls("Open material file").Delete

    ' save cell value for use by called macro
    CellValue = v

    ' If cell matches criteria add menu item and set macro to call on click
    If IsNumeric(v) Then
        If v >= 10000 And v <= 99999999 Then
            Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)

            With cBut
                .Caption = "Open URL to technical docs"
                .Style = msoButtonCaption
                .OnAction = "OpenRef"
            End With
        End If
    ElseIf v Like "OR ## #####" Then
        Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)

        With cBut
            .Caption = "Open material file"
            .Style = msoButtonCaption
            .OnAction = "OpenMat"
        End With
    End If
End Sub

在标准模块中添加此代码

Public CellValue As Variant

' replace MsgBox code with your logic to open files
Sub OpenRef()
    MsgBox "Open Reference Doc code here for " & CellValue
End Sub

Sub OpenMat()
    MsgBox "Open Material File code here for " & CellValue
End Sub

This can be achieved by adding a right click event handler to the workbook

In the Workbook module add this code

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    Dim cBut As CommandBarButton
    Dim v As Variant

    On Error Resume Next

    v = Target

    ' Remove any previously added menu items
    Application.CommandBars("Cell").Controls("Open URL to technical docs").Delete
    Application.CommandBars("Cell").Controls("Open material file").Delete

    ' save cell value for use by called macro
    CellValue = v

    ' If cell matches criteria add menu item and set macro to call on click
    If IsNumeric(v) Then
        If v >= 10000 And v <= 99999999 Then
            Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)

            With cBut
                .Caption = "Open URL to technical docs"
                .Style = msoButtonCaption
                .OnAction = "OpenRef"
            End With
        End If
    ElseIf v Like "OR ## #####" Then
        Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)

        With cBut
            .Caption = "Open material file"
            .Style = msoButtonCaption
            .OnAction = "OpenMat"
        End With
    End If
End Sub

In a standard module add this code

Public CellValue As Variant

' replace MsgBox code with your logic to open files
Sub OpenRef()
    MsgBox "Open Reference Doc code here for " & CellValue
End Sub

Sub OpenMat()
    MsgBox "Open Material File code here for " & CellValue
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文