电子邮件标题中的发送单元格体积
Sending cell volume in email title
我需要一个脚本来检查第 3 列从上到下的数字,如果它看到 0 并且它之前的数字大于 100,那么该数字的值将在电子邮件中发送 header .
当前版本的编码将所有值发送到 e-mail(条件不起作用)。
但是如果 GoTo 被替换为 Msgbox 脚本将完美运行...
For i = 2 To 100 Step 1
If cells(i, 3) = 0 And cells(i - 1, 3) < 100 Then Exit For
If cells(i, 3) = 0 And cells(i - 1, 3) > 100 Then GoTo email
If cells(i, 3) = 0 And cells(i - 1, 3) > 100 Then Exit For
Next i
email:
Dim olObj_1 As Outlook.Application
Dim mItem_1 As Outlook.MailItem
Set olObj_1 = New Outlook.Application
Set mItem_1 = olObj_1.CreateItem(olMailItem)
With mItem_1
.To = "xxxx@xxxx.com"
.Subject = "Figure_one " & cells(i - 1, 3)
.Send
End With
End Sub
试试这个:
Option Explicit
Sub Mail()
Dim i As Long
For i = 2 To 100
If Cells(i, 3) = 0 And Cells(i - 1, 3) > 100 Then
Dim olObj_1 As Outlook.Application
Dim mItem_1 As Outlook.MailItem
Set olObj_1 = New Outlook.Application
Set mItem_1 = olObj_1.CreateItem(olMailItem)
With mItem_1
.To = "xxxx@xxxx.com"
.Subject = "Figure_one " & Cells(i - 1, 3)
.Send
End With
Exit For
End If
Next i
End Sub
我假设您只想发送一封电子邮件,否则您的代码应该全部更改。
我想你可以试试这个:
Option Explicit
Sub test()
Dim olObj_1 As Outlook.Application
Dim mItem_1 As Outlook.MailItem
Dim str As String
Dim i As Long
With ThisWorkbook.Worksheets("Sheet1") ' Always select your worksheet name
For i = 2 To 100
If .Cells(i, 3).Value = 0 And .Cells(i - 1, 3).Value > 100 Then
If str = "" Then
str = "Figure_one " & .Cells(i - 1, 3).Value
Else
str = str & ", Figure_one " & .Cells(i - 1, 3).Value
End If
End With
Next i
Set olObj_1 = New Outlook.Application
Set mItem_1 = olObj_1.CreateItem(olMailItem)
With mItem_1
.To = "xxxx@xxxx.com"
.Subject = str
.Send
End With
End With
End Sub
我需要一个脚本来检查第 3 列从上到下的数字,如果它看到 0 并且它之前的数字大于 100,那么该数字的值将在电子邮件中发送 header . 当前版本的编码将所有值发送到 e-mail(条件不起作用)。 但是如果 GoTo 被替换为 Msgbox 脚本将完美运行...
For i = 2 To 100 Step 1
If cells(i, 3) = 0 And cells(i - 1, 3) < 100 Then Exit For
If cells(i, 3) = 0 And cells(i - 1, 3) > 100 Then GoTo email
If cells(i, 3) = 0 And cells(i - 1, 3) > 100 Then Exit For
Next i
email:
Dim olObj_1 As Outlook.Application
Dim mItem_1 As Outlook.MailItem
Set olObj_1 = New Outlook.Application
Set mItem_1 = olObj_1.CreateItem(olMailItem)
With mItem_1
.To = "xxxx@xxxx.com"
.Subject = "Figure_one " & cells(i - 1, 3)
.Send
End With
End Sub
试试这个:
Option Explicit
Sub Mail()
Dim i As Long
For i = 2 To 100
If Cells(i, 3) = 0 And Cells(i - 1, 3) > 100 Then
Dim olObj_1 As Outlook.Application
Dim mItem_1 As Outlook.MailItem
Set olObj_1 = New Outlook.Application
Set mItem_1 = olObj_1.CreateItem(olMailItem)
With mItem_1
.To = "xxxx@xxxx.com"
.Subject = "Figure_one " & Cells(i - 1, 3)
.Send
End With
Exit For
End If
Next i
End Sub
我假设您只想发送一封电子邮件,否则您的代码应该全部更改。
我想你可以试试这个:
Option Explicit
Sub test()
Dim olObj_1 As Outlook.Application
Dim mItem_1 As Outlook.MailItem
Dim str As String
Dim i As Long
With ThisWorkbook.Worksheets("Sheet1") ' Always select your worksheet name
For i = 2 To 100
If .Cells(i, 3).Value = 0 And .Cells(i - 1, 3).Value > 100 Then
If str = "" Then
str = "Figure_one " & .Cells(i - 1, 3).Value
Else
str = str & ", Figure_one " & .Cells(i - 1, 3).Value
End If
End With
Next i
Set olObj_1 = New Outlook.Application
Set mItem_1 = olObj_1.CreateItem(olMailItem)
With mItem_1
.To = "xxxx@xxxx.com"
.Subject = str
.Send
End With
End With
End Sub