【发布时间】:2021-11-13 10:50:43
【问题描述】:
我正在尝试将来自多个 Intranet 站点的表格屏幕截图粘贴到电子邮件中。
每个屏幕截图都粘贴到一条新消息中,而我需要它们都在同一条消息中。
循环浏览所有网址时,如何专注于初始电子邮件以粘贴所有屏幕截图?
我提到了Copying/Pasting Multiple Pictures with VBA (Excel to Outlook)。
这是我的代码:
Sub test()
Dim OutApp As Object
Dim OutMail As Object
Dim ob_urls(1 To 2) As String
Dim item As Variant
'urls
my_urls(1) = "work intranet url 1 - removed"
my_urls(2) = "work intranet url 2 - removed"
Set ie = New InternetExplorerMedium
ie.Visible = True
'loop through urls
For Each item In my_urls
ie.navigate item
'make page wide enough to see tables.
ie.Width = 1400
ie.Visible = True
Do
If ie.readyState = 4 Then
Exit Do
Else
DoEvents
End If
Loop
'delay to load before screen shot, javascript loading
Application.Wait (Now + TimeValue("0:00:7"))
'Print Screen
Application.SendKeys "(%{1068})" '
DoEvents
'Prepare the email
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "someone@org.com"
.Subject = "test"
.display
.GetInspector.Activate
'Get its Word editor
OutMail.display
Dim wordDoc As Word.document
Set wordDoc = OutMail.GetInspector.WordEditor
Application.SendKeys "(^v)"
' Crop Image
For Each shp In wordDoc.InlineShapes
shp.PictureFormat.CropTop = 200
shp.PictureFormat.CropBottom = 200
Next
End With
On Error GoTo 0
'toggle true/false to refocus
ie.Visible = False
Next item
End Sub
【问题讨论】:
-
将行从
Set OutApp =...移动到Set OutMail =...到'loop through urls之前。
标签: vba for-loop outlook screenshot paste