我有一個簡單的任務,我需要自動化。自動執行平凡的任務
我從另一個基於觸發器的應用程序以非常特定的格式獲得電子郵件。
我想要的是,看看「讀取」該電子郵件中的數據並比較兩個單元格。如果一個單元格比另一個單元格大,那麼我希望電子郵件轉發到指定的地址,否則刪除電子郵件。
下面的vba代碼被嘗試,但給出了運行時錯誤。請指導
Sub GetLines()
Dim msg As Outlook.mailItem
Dim rows As Variant
Dim numberofColumns As Long
Dim numberofRows As Long
Dim headerValues As Variant
Dim headerRow() As String
Dim data() As String
Dim i As Long, j As Long
' get currently selected email
Set msg = ActiveExplorer.Selection.item(1)
' tokenize each line of the email
rows = Split(msg.Body, vbCrLf)
' calculate array size
numberofColumns = Len(rows(0)) - Len(Replace(rows(0), Chr(9), ""))
numberofRows = UBound(rows) + 1
' put header row into array
ReDim headerRow(1 To numberofColumns)
headerValues = Split(rows(0), Chr(9))
For i = 1 To numberofColumns
headerRow(i) = Trim$(headerValues(i - 1))
Next i
' calculate data array size
numberofRows = numberofRows - 1
' put data into array
ReDim data(1 To numberofRows, 1 To numberofColumns)
For i = 1 To numberofRows
For j = 1 To numberofColumns
data(i, j) = Trim$(Split(rows(i), Chr(9))(j - 1))
Next j
Next i
End Sub
錯誤發生在哪條線上? – 2013-03-18 23:07:02
你有門檻問題嗎?記住一個100元素數組的索引從0到99,而不是1到100. – 2013-03-19 02:48:06