- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不确定为什么我的代码没有输出我的消息,即使我的电子表格有一个空字段。如果我在消息框显示它为空的值,所以不确定为什么它没有在 IsEmpty 函数中拾取它。
Sub Button1_Click()
Dim Cell As Range
Dim name As Range
Dim objDate As Date
Dim myName As String
For Each Cell In Range("P3:P4").Cells
myName = Cell.Offset(0, -14).Value
If Not IsDate(Cell.Value) Then
MsgBox "Please make sure all dates are in a valid form: DD.MM.YYYY"
ElseIf Cell.Value <= Date + 30 Then
**ElseIf IsEmpty(myName) Then
MsgBox "Please enter a name"**
Else
Dim appOutlook As Outlook.Application
Dim mitOutlookMsg As Outlook.MailItem
Dim recOutlookRecip As Outlook.Recipient
' Step 1: Initialize an Outlook session.
Set appOutlook = CreateObject("Outlook.Application")
' Step 2: Create a new message.
Set mitOutlookMsg = appOutlook.CreateItem(olMailItem)
With mitOutlookMsg
' Step3: Add the To recipient(s) to message.
Set recOutlookRecip = .Recipients.Add(myName)
recOutlookRecip.Type = olTo
'Set valid properties like Subject, Body, and Importance of the message.
.Subject = "Test123"
'.Body = "Test"
.BodyFormat = olFormatHTML
.HTMLBody = "Dear " & myName & " TEST EMAIL "
.Importance = olImportanceHigh 'High importance
' Resolve every Recipient's name
For Each recOutlookRecip In .Recipients
recOutlookRecip.Resolve
If Not recOutlookRecip.Resolve Then
mitOutlookMsg.Display
End If
Next
.Send
End With
Set mitOutlookMsg = Nothing
Set appOutlook = Nothing
MsgBox "Emails have been sent"
End If
Next Cell
End Sub
最佳答案
Cell.Value <= Date + 30
将始终返回 TRUE
当单元格为空时。
移动ElseIf IsEmpty(myName) Then
之前 ElseIf Cell.Value <= Date + 30 Then
例如
If IsEmpty(myName) Then
MsgBox "Please enter a name"
ElseIf Not IsDate(Cell.Value) Then
MsgBox "Please make sure all dates are in a valid form: DD.MM.YYYY"
ElseIf Cell.Value <= Date + 30 Then
Else
编辑:以下部分回答了您在评论中提出的问题。
如果您不想在一个单元格为空时运行代码,那么您可以使用此代码。这将检查是否 count of cells = number of cells filled
.如果它们不相同,则表示一个或多个单元格为空。
Sub Sample()
Dim rng As Range
Set rng = Range("P3:P4").Cells
If rng.Count <> Application.WorksheetFunction.CountA(rng) Then
MsgBox "Please ensure that all cells are filled with dates in the range"
Exit Sub
End If
'
'~~> Rest of the code
'
End Sub
关于vba - 代码不检查空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25241085/
我正在尝试创建一个程序,其中字符串的前三个字符重复给定次数,如下所示: foo('Chocolate', 3) # => 'ChoChoCho' foo('Abc', 3) # => 'AbcAbcA
我有以下字符串: std::string str = "Mode:AAA:val:101:id:A1"; 我想分离一个位于 "val:" 和 ":id" 之间的子字符串,这是我的方法: std::st
DNA 字符串可以是任意长度,包含 5 个字母(A、T、G、C、N)的任意组合。 压缩包含 5 个字母(A、T、G、C、N)的 DNA 字母串的有效方法是什么?不是考虑每个字母表 3 位,我们可以使用
是否有一种使用 levenstein 距离将一个特定字符串与第二个较长字符串中的任何区域进行匹配的好方法? 例子: str1='aaaaa' str2='bbbbbbaabaabbbb' if str
使用 OAuth 并使用以下函数使用我们称为“foo”(实际上是 OAuth token )的字符串加密 key public function encrypt( $text ) { // a
我是一名优秀的程序员,十分优秀!