2011-12-28 3 views
3

電子メールを1つのPSTに移動しようとしています。電子メールアイテムをあるPSTから別のPSTに移動した後に表示できない

hereのサンプルコード。

メッセージを移動コードの重要な部分:今

If objVariant.Class = olMail Or objVariant.Class = olMeetingRequest Then 

    ' This is optional, but it helps me to see in the 
    ' debug window where the macro is currently at. 
    Debug.Print objVariant.SentOn 

    ' Calculate the difference in years between 
    ' this year and the year of the mail object. 
    intDateDiff = DateDiff("yyyy", objVariant.SentOn, Now) 

    ' Only process the object if it isn't this year. 
    If intDateDiff > 0 Then 

     ' Calculate the name of the personal folder. 
     strDestFolder = "Personal Folders (" & _ 
     Year(objVariant.SentOn) & ")" 

     ' Retrieve a folder object for the destination folder. 
     Set objDestFolder = objNamespace.Folders(strDestFolder).Folders("Inbox") 

     ' Move the object to the destination folder. 
     objVariant.Move objDestFolder 

     ' Just for curiousity, I like to see the number 
     ' of items that were moved when the macro completes. 
     lngMovedMailItems = lngMovedMailItems + 1 

     ' Destroy the destination folder object. 
     Set objDestFolder = Nothing 

    End If 

、問題は、それが宛先フォルダに移動するとき、唯一メッセージヘッダーが表示され、メッセージ本体はMS Outlookのブランク来るです。

移動前のメールと移動後のメールの画像を表示することで、私が話していることをよりよく理解したいと思います。 enter image description hereenter image description here


は、さらに調査では、私は、メッセージのサイズが同じままで見つかったが、MS Outlookは、そのメッセージの本文を表示することができません。

ドラッグアンドドロップまたはコピー貼り付けを使用して手動でメッセージを移動すると、メッセージは正常に保存されます。私はメッセージ本文を見ることができます。

+0

今すぐスクリーンショットを投稿してください。 – JimmyPena

+0

自分のPSTファイルを作成しようとしていないし、メッセージをコピーするために「移動」を使用しているので、あなたの質問は実験の言い訳に過ぎません。あなたが報告した問題を再現することはできません。あなたは、VBAを経由して移動先のフォルダに体にアクセスしようとしたことがありますか?彼らは行方不明のキャラクターが不足していますか? –

答えて

1

私は可能な限りあなたのコードと環境を重複しています。私は「Personal Folders(2011)」という名前のPSTファイルを作成しました。あなたのコードと同じ方法でデスティネーションフォルダを探しました。しかし、あなたが報告したエラーを複製することはできません。私の移動したメッセージは、私が期待する通りに表示されます。

BodyFormatPropertyのMicrosoft Visual Basicのヘルプ言う:

  • を「以前のバージョンのOutlookでに、BodyFormatプロパティが表示されるか、またはそのBodyFormatプロパティはまだ設定されていないされていない、新しく作成された項目についてolFormatUnspecified定数を返しましたMicrosoft Office Outlook 2003では、このプロパティはOutlookユーザーインターフェイスで現在設定されている形式を返します。

しかし、私はこのテキストを信じていません。ボディにアクセスするまでBodyFormatプロパティが壊れているケースが発生しました。 BodyFormatプロパティに有効な値が設定されている場合にのみOutlookが本文を検索する場合は、記述する現象が発生します。これは、(1)壊れていないボディが実際に移動されたメッセージに存在するかどうか、(2)ボディにアクセスすることで問題がプログラムで解決されることを知りたいのです。

次のマクロ(またはそのようなもの)を実行して、出力の性質を報告してください。有効なメッセージのために

Sub DebugMovedMessages() 

    Dim Body As String 
    Dim FolderTgt As MAPIFolder 
    Dim ItemClass As Integer 
    Dim ItemCrnt As Object 
    Dim NameSpaceCrnt As NameSpace 

    Set NameSpaceCrnt = CreateObject("Outlook.Application").GetNamespace("MAPI") 

    ' ######### Adjust chain of folder names as required for your system 
    Set FolderTgt = NameSpaceCrnt.Folders("Personal Folders (2011)") _ 
             .Folders("Inbox").Folders("CodeProject") 

    For Each ItemCrnt In FolderTgt.Items 
    With ItemCrnt 

     ' This code avoid syncronisation errors 
     ItemClass = 0 
     On Error Resume Next 
     ItemClass = .Class 
     On Error GoTo 0 

     If ItemClass = olMail Or ItemClass = olMeetingRequest Then 
     Debug.Print IIf(ItemClass = olMail, "Mail", "Meeting") & _ 
                 " item " & .SentOn 
     Body = .Body 
     Debug.Print " Length of text body = " & Len(Body) 
     Call DsplDiag(Body, 4, 25) 
     If ItemClass = olMail Then 
     Body = .HTMLBody 
     Debug.Print " Length of html body = " & Len(Body) 
     Call DsplDiag(Body, 4, 25) 
     End If 
     End If 
    End With 
    Next 

End Sub 
Sub DsplDiag(DsplStg As String, DsplIndent As Integer, DsplLen As Integer) 

    Dim CharChar As String 
    Dim CharInt As Integer 
    Dim CharStg As String 
    Dim CharWidth As Integer 
    Dim HexStg As String 
    Dim Pos As Integer 
    Dim Printable As Boolean 

    CharStg = Space(DsplIndent - 1) 
    HexStg = Space(DsplIndent - 1) 

    For Pos = 1 To DsplLen 
    CharChar = Mid(DsplStg, Pos, 1) 
    CharInt = AscW(CharChar) 
    Printable = True 
    If CharInt > 255 Then 
     CharWidth = 4 
     ' Assume Unicode character is Printable 
    Else 
     CharWidth = 2 
     If CharInt >= 32 And CharInt <> 127 Then 
     Else 
     Printable = False 
     End If 
    End If 
    HexStg = HexStg & " " & Right(String(CharWidth, "0") & _ 
               Hex(CharInt), CharWidth) 
    If Printable Then 
     CharStg = CharStg & Space(CharWidth) & CharChar 
    Else 
     CharStg = CharStg & Space(CharWidth + 1) 
    End If 
    Next 

    Debug.Print CharStg 
    Debug.Print HexStg 

End Sub 

、これらのマクロは、出力がイミディエイトウィンドウに次のようなものでしょう:私はあなたがこのような出力を得ることであると思います何

Mail item 23/12/2011 05:09:58 
    Length of text body = 10172 
    y o u r  d a i l y  d e a l    H Y P E R L 
    79 6F 75 72 20 64 61 69 6C 79 20 64 65 61 6C 20 09 0D 0A 48 59 50 45 52 4C 
    Length of html body = 32499 
    < ! D O C T Y P E  h t m l  P U B L I C  " -/
    3C 21 44 4F 43 54 59 50 45 20 68 74 6D 6C 20 50 55 42 4C 49 43 20 22 2D 2F 
Mail item 29/12/2011 11:03:38 
    Length of text body = 173 
    A 1 = ¡  F F = ÿ  1 0 0 = A    1 E 0 0 = ?  
    41 31 3D A1 20 46 46 3D FF 20 31 30 30 3D 0100 A0 20 31 45 30 30 3D 1E00 20 0D 
    Length of html body = 0 

。つまり、メッセージ本文が存在し、正しいことを願っています。私はさらに、身体にアクセスしたことを期待して、Outlookはそれらを表示することができます。私が正しいとすれば、身体を動かす前に体にアクセスすることができます。それができない場合は、新しく移動したメッセージにアクセスするためのルーチンが必要ですが、表示はありません。

+0

あなたのソリューション私を助けて、 問題がMailItem.Bodyとあったおかげで、メールが移動された後、何らかの理由で、mMailItem.Bodyは「」=になるために使用しますが、、その後、私はプログラム的に新しい移動メールオブジェクト、mMailItem1を設定します。 mMailItem.BodyにボディとmMailItem1

Dim mMailItem1 As Outlook.MailItem Set mMailItem1 = mMailItem.Move(mobjDestFolder) 
Shabbir

+0

を保存するには、私は助けになることを嬉しく思います。私は、Outlookは、体が存在しているので、私は驚いていないだと認識していないとの問題がありました。 –

関連する問題