2016-08-12 16 views
3

ユーザーが検索した条件に一致する電子メールの件名を変更するマクロを作成しようとしています。その後、OutlookでVBAで選択した項目の件名を変更する

だから、自分の受信トレイで例えば、ユーザー検索「りんご」と件名に[APPLES]を持つようにリンゴに関連するすべての電子メールを変更するには、このマクロを使用しています。

問題は、私が今コードを変更したのは、ユーザーがクリックした電子メールの件名だけであり、選択した電子メールのすべてではないという点です。私はかなりVBAの新人ですが、私はそれがActiveExplorerと私が使用している選択機能と関係があると確信しています。ここで

はコードです:

Sub AddString() 
Dim myolApp As Outlook.Application 
Dim aItem As Object 

Set myolApp = CreateObject("Outlook.Application") 
Set mail = myolApp.ActiveExplorer.CurrentFolder 
Dim iItemsUpdated As Integer 
Dim strTemp As String 
Dim strString As String 
Dim myOlExp As Outlook.Explorer 
Dim myOlSel As Object 


' User input 
strString = InputBox("Enter the project code") 
iItemsUpdated = 0 

' Empty value or cancel button 
If strString = "" Then Exit Sub 

' Writes string to e-mail subject 
Set myOlExp = myolApp.ActiveExplorer 
Set myOlSel = myOlExp.Selection 
For x = 1 To myOlSel.Count 
    strTemp = "[" & strString & "] " & myOlSel.Item(x).Subject 
    myOlSel.Item(x).Subject = strTemp 
    myOlSel.Item(x).Save 
    iItemsUpdated = iItemsUpdated + 1 
Next x 

' Tells user how many items have been updated 
MsgBox iItemsUpdated & " of " & mail.Items.Count & " Messages Updated" 
Set myolApp = Nothing 
End Sub 

答えて

1

ちょうど

' Writes string to e-mail subject 
Set myOlExp = myolApp.ActiveExplorer 
myOlExp.SelectAllItems 
Set myOlSel = myOlExp.Selection 
のように、あなたのコードに myOlExp.SelectAllItemsを追加します
関連する問題