目前,我正在使用此腳本使Outlook電子郵件中的數據始終替換A1中的數據。將數據插入到第一行而不是工作表的最後一行
Const xlUp As Long = -4162
Sub ExportToExcel(MyMail As MailItem)
Dim strID As String, olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim strFileName As String
'~~> 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:\Users\admin\Desktop\Control Panel.xlsm")
'~~> Set the relevant output sheet. Change as applicable
Set oXLws = oXLwb.Sheets("Sheet1")
lRow = oXLws.Range("A" & oXLApp.Rows.Count).End(xlUp).Row + 0
'~~> Write to outlook
With oXLws
'
'~~> Code here to output data from email to Excel File
'~~> For example
'
.Range("A" & lRow).Value = olMail.Body
'
End With
'~~> Close and Clean up Excel
oXLwb.save
Set oXLws = Nothing
Set oXLwb = Nothing
Set oXLApp = Nothing
Set olMail = Nothing
Set olNS = Nothing
End Sub
如果Row + 0
使其覆蓋數據, 和Row + 1
使它進入下一個可用的電池,我怎樣才能讓這個最新的數據總是會進入例如,A1,然後使舊的信息向下移動?
任何提示讚賞。在理解腳本方面,我不是很聰明。我試過Row - 1
,顯然它沒有工作。
我要說你需要發佈完整的代碼。您需要做的更改不在您發佈的部分。 [編輯]你的問題並添加代碼。 –
嗨,編輯的代碼,感謝您的幫助:) – Rachael