受信メールを処理するコードを記述しています。ほとんどの側面は正しく動作しています。しかし、日付の処理は私にいくつかの問題を与えている。 Module1で定義したEvaluateDate関数が正しく動作していません。私はそれを実行するときにエラーはありません、ただ出力はありません。 Tablは部分文字列の配列です。着信電子メールは、行ごとに部分文字列に分割されます。したがって、基本的に配列の各インデックスは電子メールの行です。私は特定の月を検索し、1月などに "01 /"を割り当てようとしています。着信電子メールは「2011年10月20日木曜日」のようなもので、「10/20/11」に処理されたい。すべてがString型です。どんな助けでも大歓迎です。問題の原因を特定するために他のコードが必要な場合はお知らせください。ありがとう。シート1つのコードで特定の文字列(VBA)の部分文字列の検索
、Module1ので
Public Sub CommandButton1_Click()
Dim olApp As New Outlook.Application
Dim olExp As Outlook.Explorer
Dim olSel As Outlook.Selection
Dim myArray(8) As String
Dim Line As Long, Addr1 As String
Dim Tabl, str As String
Dim index As Integer
Dim I As Integer, x As Integer, N As Integer, j As Integer
Sheets("EditData").Select
Columns("D:D").NumberFormat = "@"
'Selection.NumberFormat = "@"
On Error Resume Next
' Getting the messages selection
Set olApp = Outlook.Application
Set olExp = olApp.ActiveExplorer
Set olSel = olExp.Selection
' Checking if there is at least one message selected
If olSel.Count < 1 Then
MsgBox "No message selected", vbExclamation, "Error"
Exit Sub
End If
With Sheets("EditData")
' Retrieving the first avaible row to put message in
Line = .Range("D65000").End(xlUp).Row + 1
' looping through message
For x = 1 To olSel.Count
DoEvents
Erase myArray
mybody = Replace(olSel.Item(x).body, Chr(13), "")
' Splitting the message body into an array of substrings,
' using the "line feed" characters as separators
mybody = Replace(mybody, Chr(10) & Chr(10), Chr(10))
Tabl = Split(mybody, Chr(10))
For Each Item In Tabl
Item = Replace(Item, Chr(10), "")
Item = Application.Clean(Item)
Next Item
' Looping through these substrings
For I = 0 To UBound(Tabl)
' Date Received Start
If LCase(Left(Tabl(I), 4)) = "sent" Then
m = Module1.EvaluateDate(Tabl)
.Cells(Line, 2) = m
End If
Next I
Next X
End With
End Sub
、
'Function to determine the month, day, and year in this format mm/dd/yy
Public Function EvaluateDate(Tabl As Variant) As Variant
For I = 0 To UBound(Tabl)
If InStr(1, Tabl(I), "January", 1) > 0 Then
m = "01/"
End If
If InStr(1, Tabl(I), "February", 1) > 0 Then
m = "02/"
End If
If InStr(1, Tabl(I), "March", 1) > 0 Then
m = "03/"
End If
If InStr(1, Tabl(I), "April", 1) > 0 Then
m = "04/"
End If
If InStr(1, Tabl(I), "May", 1) > 0 Then
m = "05/"
End If
If InStr(1, Tabl(I), "June", 1) > 0 Then
m = "06/"
End If
If InStr(1, Tabl(I), "July", 1) > 0 Then
m = "07/"
End If
If InStr(1, Tabl(I), "August", 1) > 0 Then
m = "08/"
End If
If InStr(1, Tabl(I), "September", 1) > 0 Then
m = "09/"
End If
If InStr(1, Tabl(I), "October", 1) > 0 Then
m = "10/"
End If
If InStr(1, Tabl(I), "November", 1) > 0 Then
m = "11/"
End If
If InStr(1, Tabl(I), "December", 1) > 0 Then
m = "12/"
End If
Next I
EvaluateDate = m
End Function
コードを適切な書式で修正してください。 – Polynomial
vb6、vba、vbscript、またはvb.net? –