微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

需要将公共子代码的结果粘贴到新的Word文档标题中,并将整个电子邮件复制并粘贴到标题下

如何解决需要将公共子代码的结果粘贴到新的Word文档标题中,并将整个电子邮件复制并粘贴到标题下

到目前为止,这是我的代码

Public Sub CCReceiptPrintFirstPage()
Dim Mail As Outlook.MailItem
Set Mail = Application.ActiveExplorer.Selection(1)
PrintFirstPage Mail

End Sub

Public Sub GetInvoiceValue(Mail As Outlook.MailItem)

Dim olMail As Outlook.MailItem
Dim Inv1 As InvoiceN
Dim M1 As MatchCollection
Dim M As Match

Set olMail = Application.ActiveExplorer().Selection(1)
' Debug.Print olMail.Body

Set Inv1 = New RegInvoiceN

' \s* = invisible spaces
' \d* = match digits
' \w* = match alphanumeric

With Inv1
    .Pattern = "Quote/Work Order/Invoice Number\s*+(\w*)\s*"
    .Global = True
End With
If Inv1.test(olMail.Body) Then

Set M1 = Inv1.Execute(olMail.Body)
For Each M In M1
    ' M.SubMatches(1) is the (\w*) in the pattern
    ' use M.SubMatches(2) for the second one if you have two (\w*)
    Debug.Print M.Submatches(1)
    
Next
End If

End Sub

Public Sub PrintFirstPage(Mail As Outlook.MailItem)
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim olDoc As Word.Document
Dim wdLine As Word.Document

Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add(Visible:=True)
Set olDoc = Mail.GetInspector.WordEditor
Set wdLine = wdApp.Documents.Add(Visible:=True)


"NEED THE NEW VBA CODE HERE,BEFORE copYING AND PASTING THE ENTIRE EMAIL"
olDoc.Range.copy
wdDoc.Range.Paste

wdDoc.PrintOut Range:=wdPrintFromTo,From:="1",To:="1"

DoEvents
wdDoc.Close False
wdLine.Close False
wdApp.Quit
End Sub

我需要使我的代码使用Public Sub GetInvoiceValue的结果,并在显示“在复制和粘贴整个电子邮件之前需要此处新VBA代码”的地方插入值。如果操作正确,应在复制整个电子邮件并将其粘贴到Microsoft Word标头下方之前,先将发票编号粘贴到Microsoft Word标头中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。