我在论坛上找到的excel宏遇到了一些麻烦,但我无法解决问题,因为我不知道我在寻找什么来修复它。
首先,我将解释我想要做什么,然后我将粘贴我正在使用的VBA以便做我想要的。
目前,我正在将整个电子邮件的内容放到下面复制数据的行中,我似乎无法改变它的位置(此时它进入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("\\server-01\company\Rachael\VBAs\Control Panel Visual Layout.xlsm")
'~~> Set the relevant output sheet. Change as applicable
Set oXLws = oXLwb.Sheets("Control Panel")
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.Body
'
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
End Sub
任何和所有的帮助将不胜感激,我花了大约2周的时间从谷歌尝试各种各样的事情,无济于事!