我创建了一个供我的会计部门使用的宏工作簿。宏工作簿包含动态宏,可由不同用户出于多种不同原因使用。为了更进一步,我在宏工作簿中创建了一个前菜单,其中包含为每个宏指定的命令按钮,以及该宏的命令按钮旁边的单元格中的描述。
我希望用户单击他们想要的宏的命令按钮,然后从不同的工作簿中选择要执行的宏的电子表格。下面是一个示例宏。本质上,我试图找出如何避免用户必须使用 Alt + F8 来选择并运行宏工作簿中的宏,方法是允许用户选择他们选择的命令按钮。
步骤将是:
我被困在如何构建逻辑以将步骤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
答案 0 :(得分:1)
你好,所以这里是我在你们每个人的按钮中输入这个代码而不是切换子名称的例子我把你的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