【问题标题】:Pasting multiple screenshots to single Outlook email将多个屏幕截图粘贴到单个 Outlook 电子邮件
【发布时间】: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


【解决方案1】:

我想出了这个。

代替:

    'Prepare the email
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)

这样做会在一封电子邮件中获取所有屏幕截图:

    If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    If OutMail Is Nothing Then Set OutMail = OutApp.CreateItem(0)

和平。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    相关资源
    最近更新 更多