vba - 如何通过vba发送自动选择的范围
问题描述
我正在使用下面的代码从两个不同的工作表中选择范围并通过电子邮件发送。这一切都很好,但是当我运行代码时,选定的范围会被放入一个新的电子邮件窗口,但不会自动发送。我尝试在“.HTMLBody”之后添加“.send”,但似乎不起作用。任何帮助,将不胜感激。
子到期()
Dim ol As Object 'Outlook.Application
Dim olEmail As Object 'Outlook.MailItem
Dim olInsp As Object 'Outlook.Inspector
Dim wd As Object 'Word.Document
Dim rCol As Collection, r As Range, i As Integer
'/* if outlook is running use GO, create otherwise */
Set ol = GetObject(Class:="Outlook.Application")
Set olEmail = ol.CreateItem(0) 'olMailItem
Set rCol = New Collection
With rCol
.Add Sheet1.Range("A1:p52") '/* add your ranges the same sequence */
.Add Sheet2.Range("A1:p17") '/* as you want them added in the body */
End With
With olEmail
.To = ""
'/* bonus basic html */
.HTMLBody = "<html><body style=""font-family:calibri"">" & _
"<p><b>Dear Deer,</b><br><br> She see seas." & _
"</p></body></html>"
Set olInsp = .GetInspector
If olInsp.EditorType = 4 Then 'olEditorWord
Set wd = olInsp.WordEditor
For i = 1 To rCol.Count '/* iterate all ranges */
Set r = rCol.Item(i): r.Copy
wd.Range.InsertParagraphAfter
wd.Paragraphs(wd.Paragraphs.Count).Range.PasteAndFormat 16
'16 - wdFormatOriginalFormatting
Next
End If
wd.Range.InsertParagraphAfter
wd.Paragraphs(wd.Paragraphs.Count).Range.Text = "Regards, Patricia"
wd.Paragraphs.Last.Range.Sentences.Last.Font.Bold = True
.Display
End With
结束子
解决方案
改变这个:
wd.Paragraphs.Last.Range.Sentences.Last.Font.Bold = True
.Display
End With
至
wd.Paragraphs.Last.Range.Sentences.Last.Font.Bold = True
.Send
End With
推荐阅读
- mysql - 如何减少被扫描的行数?
- c# - GetEnumerator movenext System.NullReferenceException
- python - 用于自动完成/热键输入的 Pynput 监听器
- javascript - 如何无限次重复 React 元素?
- android - Android 无法获取正确的数据库路径
- javascript - 使用 javascript 或 Jquery 过滤 JSON GraphQL 数据
- gcloud - gcloud app deploy 灵活环境挂起
- admob - 即使在商品详情中添加开发者网站 10 天后,Admob 也无法抓取 app-ads.txt
- flutter - 如何使底栏随键盘向上移动(颤动)
- javascript - 从 CDN 加载 jquery 脚本有效,但从 IIS 加载相同的脚本会产生非法字符?