簡體   English   中英

如何從電子郵件(Outlook)提取內容到Excel表?

[英]How to extract content from an E-Mail (Outlook) to an excel table?

我正在嘗試通過VBA將Outlook中的電子郵件中的內容提取到Excel表中。
該電子郵件用於假期管理。
在該主題中,總是有關鍵字“ Accepted holiday-James先生” James先生是員工的名字,該假期被接受。 因此,關鍵字“ Accepted holiday”始終相同,但名稱始終會更改。
電子郵件包含一個長表,但是只需要結尾。 如果它正在搜索一些關鍵字,也許是最好的。
Datum von 18.12.2014
Datum之二18.12.2014
塔吉1

我不知道使用VBA有哪些可能性。
我是一個新手,這是我第一次使用VBA。
感謝您的幫助。

真誠的,塞巴斯蒂安

Excel文件包含:第1行和第2行為空。
第3行包含一年中的日期。
第4行包含Mo,Tue,Wed,Thur,Fr,Sat,Sun
第5行是空的
A6,A7,A8,...行包含工作人員名稱
然后在第6、7、8行中,工人假期的日子應為“ X”。

常量xlUp只要-4162

Sub ExportToExcel(MyMail作為MailItem)Dim strID作為字符串,olNS作為Outlook.Namespace Dim olMail作為Outlook.MailItem Dim strFileName作為字符串

'~~> Excel Variables
Dim oXLApp As Object, oXLwb As Object, oXLws As Object
Dim lRow As Long

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)

'~~> Establish an EXCEL application object
On Error Resume Next
Set oXLApp = GetObject(, "Excel.Application")

'~~> If not found then create new instance
If Err.Number <> 0 Then
    Set oXLApp = CreateObject("Excel.Application")
End If
Err.Clear
On Error GoTo 0

'~~> Show Excel
oXLApp.Visible = True

'~~> Open the relevant file
Set oXLwb = oXLApp.Workbooks.Open("C:\Sample.xls")

'~~> Set the relevant output sheet. Change as applicable
Set oXLws = oXLwb.Sheets("Sheet1")

lRow = oXLws.Range("A" & oXLApp.Rows.Count).End(xlUp).Row + 1

'~~> Write to outlook
With oXLws
    '
    '~~> Code here to output data from email to Excel File
    '~~> For example
    '
    .Range("A" & lRow).Value = olMail.Subject
    .Range("B" & lRow).Value = olMail.SenderName
    '
End With

'~~> Close and Clean up Excel
oXLwb.Close (True)
oXLApp.Quit
Set oXLws = Nothing
Set oXLwb = Nothing
Set oXLApp = Nothing

Set olMail = Nothing
Set olNS = Nothing

結束子

看來您需要從Outlook自動執行Excel。 如何從Visual Basic自動執行Microsoft Excel文章介紹了所有必需的步驟。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM