gpt4 book ai didi

vba - 按正常顺序将剪贴板粘贴到 Outlook 电子邮件中

转载 作者:行者123 更新时间:2023-12-05 00:11:58 25 4
gpt4 key购买 nike

我有 5 个用于电子邮件的用户表单。工作流程是这样的:

create new email

userform1.show
user selects the fields
automatic printscreen is inserted in the text

userform2.show
user selects the fields
automatic printscreen is inserted in the text

userform3.show
user selects the fields
automatic printscreen is inserted in the text

userform4.show
user selects the fields
automatic printscreen is inserted in the text

userform5.show
user selects the fields
automatic printscreen is inserted in the text

我的问题是,最终电子邮件将如下所示:

userform1 selected fields
userform2 selected fields
userform3 selected fields
userform4 selected fields
userform5 selected fields

print screen 5
print screen 4
print screen 3
print screen 2
print screen 1

有没有办法让打印屏幕以正确的顺序出现?

这是为第一个用户窗体复制剪贴板的代码(打印屏幕来自另一个应用程序)

Dim olInsp As Object
Dim oRng As Object
Dim wdDoc As Object

With objItem

Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range
oRng.collapse 1
objItem.Display
objItem.Visible = True
objItem.HtmlBody = "<br><br>" & objItem.HtmlBody

On Error Resume Next
oRng.Paste

objItem.HtmlBody = "<br>" & objItem.HtmlBody

Dim myOutlook As Object
Set myOutlook = GetObject(, "Outlook.Application")
myOutlook.ActiveExplorer.Activate

End With

我让光标移动到邮件的末尾,但粘贴根本不起作用

Dim objCurrentMail As Outlook.MailItem
Dim objWordDocument As Word.Document
Dim objWordRange As Word.Range
Dim VarPosition As Variant

'Only work if the current email is using word editor
Set objCurrentMail = Outlook.Application.ActiveInspector.CurrentItem
Set objWordDocument = objCurrentMail.GetInspector.WordEditor


VarPosition = objWordDocument.Range.End - 1000
Set objWordRange = objWordDocument.Range(VarPosition, VarPosition)
objWordRange.Select

keybd_event VK_DOWN, 0, 0, 0
keybd_event VK_DOWN, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_CONTROL, 0, 0, 0
keybd_event VK_V, 0, 0, 0
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_V, 0, KEYEVENTF_KEYUP, 0

最佳答案

这里有代码将光标移动到末尾http://www.vboffice.net/en/developers/determine-cursor-position/

Public Sub SetCursor()
Dim Ins As Outlook.Inspector
Dim Doc As Word.Document
Dim range As Word.range
Dim pos As Long

Set Ins = Application.ActiveInspector
Set Doc = Ins.WordEditor
If Not Doc Is Nothing Then
pos = Doc.range.End - 1
Set range = Doc.range(pos, pos)
range.Select
End If
End Sub

您的代码可能如下所示:

Option Explicit

Sub pasteAtEnd()

Dim olInsp As Object
Dim oRng As Object
Dim wdDoc As Object

Dim pos As Long
Dim objItem As Object

Set objItem = ActiveInspector.currentItem

With objItem

Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.range

objItem.Display
'objItem.HTMLBody = "<br><br>" & objItem.HTMLBody
objItem.HTMLBody = objItem.HTMLBody & "<br><br>"

pos = wdDoc.range.End - 1
Set oRng = wdDoc.range(pos, pos)
oRng.Select

MsgBox "Cursor should be at end of the mail body."

'On Error Resume Next ' Use proper error handling
oRng.Paste

End With

End Sub

关于vba - 按正常顺序将剪贴板粘贴到 Outlook 电子邮件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44693988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com