使用命令button在任何所需的工作簿/电子表格上执行macros

我创build了一个供我的会计部门使用的macros观工作簿。 macros工作簿包含dynamicmacros,可以由不同的用户由于许多不同的原因使用。 为了更进一步,我已经在macros工作簿中创build了一个前菜单,该菜单为每个macros指定了一个命令button,并在该macros的命令button旁边的单元格中有一个描述。

我想让用户点击他们想要的macros的命令button,然后从不同的工作簿中select电子表格来执行macros。 下面是一个示例macros。 实质上,我试图找出如何避免用户必须使用Alt + F8来select并运行macros工作簿中的macros,方法是允许用户select自己select的命令button。

步骤是:

  1. 用户将下载一个报告或将打开一个工作簿,他们想要执行该macros的一般macros工作簿
  2. 用户将打开保存在其中一个共享驱动器中的常规macros工作簿
  3. 用户将点击前面菜单上显示的macros执行button。 这将触发macros执行,但直到用户切换并select工作簿和电子表格来执行macros时才会发生。
  4. 用户select所需的工作簿和电子表格确认应用macros,macros将执行

我被困在如何build立链接步骤3到步骤4的逻辑。

Sub fill_in() 'Fills in blank cells with populated cells above 'could help with filling in GL's for a set number of rows below 'could help with filling in Property IDs or Resident IDs, etc. Dim col As String col = InputBox("Enter Column Letter to find Last Row") Dim lrow As Long lrow = Cells(Rows.Count, col).End(xlUp).Row Dim StartRow As Long Dim StartCol As String Dim EndCol As String StartRow = InputBox("Enter Beginning Row # for Range") StartCol = InputBox("Enter Beginning Column Letter for Range") EndCol = InputBox("Enter Last Column Letter for Range") Dim Rg As Range Set Rg = Range(Cells(StartRow, StartCol), Cells(lrow, EndCol)) 'Fill data for each cell below Dim MyCounter As Long MyCounter = 0 For Each r In Rg On Error Resume Next If r.Value = "" Then r.Value = r.Offset(-1, 0).Value End If Next End Sub 

你好所以这里是我得到你在每一个button把这个代码比切换出子例如我把你的fill_in子代码在这个代码只是改变它

 Dim wb As Workbook Dim sheet As Worksheet Dim YesOrNoAnswerToMessageBox As String For Each wb In Application.Workbooks YesOrNoAnswerToMessageBox = MsgBox("Would you like to run the macro on " & wb.Name & "?", vbYesNo, "Where to run marco?") If YesOrNoAnswerToMessageBox = vbYes Then wb.Activate With wb For Each sheet In wb.Worksheets YesOrNoAnswerToMessageBox = MsgBox("Would you like to run the macro on worksheet " & sheet.Name & "?", vbYesNo, "Where to run marco?") If YesOrNoAnswerToMessageBox = vbYes Then sheet.Activate 'Put sub name here fill_in End If Next sheet End With End If Next wb