excel - VBA如何显示两个带有符号的msgbox?
问题描述
Dim fg As Double
Dim msg1 As String
Dim msg2 As String
Dim result As Integer
Dim percent As Double
fg = Cells(8, 10).Value
percent = Application.WorksheetFunction.roundup(fg * 100, 2)
msg1 = "Fat as percentage of calories consumed:" & percent & "%"
msg2 = "Recommended total fat intake: less than 30% of total calories."
msg3 = "you are suggested to change your food choice to lower the fat"
If fg > 0.3 Then
MsgBox msg1
MsgBox msg2, vbExclamation
result=MsgBox msg3, vbYesNo
If result = vbYes Then
ThisWorkbook.Sheets("Weekly Meal Planner").Activate
end if
If result = vbNo Then
ThisWorkbook.Sheets("DAILY LOG").Activate
End If
End If
If fg < 0.3 Then MsgBox (msg1)
End Sub
为什么当我单击“确定”时程序无法显示“每周膳食计划”表
解决方案
你不需要把它们放在同一条线上。
这是 if 语句的工作原理。
If fg > 0.3 Then
MsgBox msg2, vbExclamation
MsgBox msg1
End If
MsgBox
仅当您需要返回值时才使用括号:
Dim result as Variant
result = MsgBox(msg3, vbYesNo)
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/msgbox-function
要将其用作Subroutine
,请不要使用括号。
MsgBox "test"
要将其用作Function
,请包含括号。
result = MsgBox("test")
您还可以使用图标和按钮选择:
result = MsgBox("Are you sure?", vbQuestion + vbYesNo)
推荐阅读
- dart - 如何使用 Null Safety 将项目添加到列表
- php - laravel中如何使用多个入口文件来控制路由
- android - Jetpack Compose PointerInput 状态提升
- javascript - SheetJS table_to_sheet 显示空白行
- python - 使用客户端集成进行付款时如何运行 django 功能
- quantum-computing - 从当前状态到目标状态(App QLogic)
- google-signin - Google One Tap 提示显示域名而不是应用程序名称
- css - CSS?选择器不适用于 SCSS 选择器
- react-native - 点击 FlatList 底部的 TextInput,键盘会立即关闭,
- sql - PL/SQL 检查一个数是否为素数的函数