我之前只编写了非常基本的vba代码所以我知道了一点,我通常可以弄清楚大多数代码在阅读时所做的事情,但我现在想要做的就是超出我的能力。我找到了谷歌搜索的一些基本代码,并添加了一些标签来描述我想要的每一行。
基本上,如果您查看excel工作表的下图,我想点击学生姓名并点击一个按钮(或其他内容),它将在gmail中生成一封电子邮件,其中列出了学生缺失的所有作业。
感谢您的帮助!
Sub email()
Const username = "me@school.org"
Const password = "password"
Dim objEmail, objConfig
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "me@school.org"
objEmail.To = "me@school.org" 'I want the To address to be loaded based on a cell in the selected column'
objEmail.Subject = "missing assignments"
objEmail.cc = "advisor@school.org" 'I want the CC address to be loaded based on a cell in the selected column'
Do While Len(objEmail.TextBody) = 0 ‘I’m not sure what this line of code is doing’
objEmail.TextBody = “You are missing the below assignments”
‘what do I add if I then want the body of the email to be a range of cells, based on the column currently selected?’
Loop
Set objConfig = objEmail.Configuration
objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtp.gmail.com
'I don't know what this is for my school, we use gmail, but the address is not @gmail'
objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/sendusername") = username
objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
objConfig.Fields.Update
objEmail.Display 'I want to display before sending
Set objEmail = Nothing
Set objConfig = Nothing
End Sub