大家好
我正在用4个不同的模块做一个宏。 前3个模块用于格式化不同的文件,而如果我想一次格式化所有文件,我将单击模块4。 前3个模块有一个消息框,其中包含格式化的摘要报告,但是,如果我通过模块4调用模块,我不想打开这些消息框。
以下是我的代码,但由于Summary(对vbYesNo的响应)的值未转移到第1单元,因此无效:
模块4代码:
Sub FormatAll_Click()
YesNo = MsgBox("Do you want to show Report Summary after formatting each CSA Report?", vbYesNo + vbQuestion, "Report Summary")
Summary = YesNo
Module1.FORMAT_1st_Report
Module2.FORMAT_2nd_Report
Module3.FORMAT_3rd_Report
MsgBox "Done formatting all documents", vbInformation, "Done"
End Sub
模块1代码:
If Summary <> vbNo Then
MsgBox "Done Formatting Purchasing Document Creation Report" & vbNewLine & "Summary:" & vbNewLine & " Successful: " & s & vbNewLine & " Empty Worksheet: " & e & vbNewLine & " Failed: " & f, vbInformation, "SUMMARY REPORT"
If s > 0 Then
Dim YesNo As String
YesNo = MsgBox("Do you want to open all successfully formatted file?", vbYesNo + vbQuestion, "Open File")
If YesNo = vbYes Then
Module14.OpenPOCreation
End If
End If
End If
答案 0 :(得分:1)
将一个默认值为0的可选参数添加到其他子组,并从Summary
传递FormatAll_Click
。
E.g。 -
Sub FormatAll_Click()
Dim Summary
Summary = MsgBox("Do you want to show Report Summary after formatting" & _
" each CSA Report?", vbYesNo + vbQuestion, "Report Summary")
Module1.FORMAT_1st_Report Summary
Module2.FORMAT_2nd_Report Summary
Module3.FORMAT_3rd_Report Summary
MsgBox "Done formatting all documents", vbInformation, "Done"
End Sub
Sub FORMAT_1st_Report(Optional response = 0)
If response = vbYes Then
MsgBox "Called with vbYes"
Else
MsgBox "Not called with vbYes"
End If
End Sub