本文介绍了Excel VBA - 从代码中读取单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从excel发送电子邮件的任务。
下面是示例列。如何从循环中获取电子邮件的值?
感谢

task to send email from excel.Below is the example column. How I can get the email value from the loop?Thanks

这是我的代码:


   Dim rng As Range
   Dim row As Range
   Dim cell As Range
   Dim mydate As Date
   Dim myDiff As Long

设置rng =范围(E5:E17)
设置rng2 =范围(F5:F17)
Dim cell2 As Range

Set rng = Range("E5:E17")Set rng2 = Range("F5:F17")Dim cell2 As Range

Dim i As Integer
i = 5

Dim i As Integeri = 5

对于每行在rng.Rows
对于每个单元格在row.Cells

For Each row In rng.Rows For Each cell In row.Cells

MsgBox cell.Value
mydate = cell.Value
myDiff = DateDiff("d", Date, mydate)

Set rng2 = Range("F" & i)
For Each cell2 In rng2
 MsgBox cell2.Value
Next cell2

如果myDiff> -8和myDiff< 8然后
aEmail.Send
结束如果

If myDiff > -8 And myDiff < 8 Then aEmail.SendEnd If

i = i + 1
下一个单元格
下一行

i = i + 1 Next cellNext row

推荐答案

我想你需要这个..

Dim n as Integer

For n = 5 to 17
  msgbox cells(n,3) '--> sched waste
  msgbox cells(n,4) '--> type of treatm
  msgbox format(cells(n,5),"dd/MM/yyyy") '--> Lic exp
  msgbox cells(n,6) '--> email col
Next

这篇关于Excel VBA - 从代码中读取单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:22