Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在Outlook中,替换或删除邮件中的inlineshapes只工作一次_Vb.net_Outlook - Fatal编程技术网

Vb.net 在Outlook中,替换或删除邮件中的inlineshapes只工作一次

Vb.net 在Outlook中,替换或删除邮件中的inlineshapes只工作一次,vb.net,outlook,Vb.net,Outlook,我在vb.net中编程了一个outlook加载项,它可以在outlook 2010中保存邮件。 用户可以决定将附件与邮件一起保存,也可以单独保存 无论邮件是否有附件,加载项都可以正常工作并保存邮件。 该插件还可以保存邮件的可能内联形状 但只有一次 如果我用一个或多个inlineshape保存邮件,一切正常(保存inlineshape、用文本替换inlineshape或删除邮件中的inlineshape、将邮件保存到磁盘) 之后,如果我接收另一封带有inlineshape的邮件,保存工作正常,但替

我在vb.net中编程了一个outlook加载项,它可以在outlook 2010中保存邮件。 用户可以决定将附件与邮件一起保存,也可以单独保存

无论邮件是否有附件,加载项都可以正常工作并保存邮件。 该插件还可以保存邮件的可能内联形状

但只有一次

如果我用一个或多个inlineshape保存邮件,一切正常(保存inlineshape、用文本替换inlineshape或删除邮件中的inlineshape、将邮件保存到磁盘)

之后,如果我接收另一封带有inlineshape的邮件,保存工作正常,但替换或删除inlineshape不起作用

为什么? 我做错了什么

非常感谢你的帮助

这是调用保存邮件、附件和inlineshapes的函数的代码:

Dim outlookApp As Outlook.Application
Dim outlookExp As Outlook.Explorer
Dim outlookSel As Outlook.Selection

outlookApp = New Outlook.Application
outlookExp = outlookApp.ActiveExplorer
outlookSel = outlookExp.Selection 

For i As Integer = 1 To outlookSel.Count
   outlookObject = outlookSel.Item(i)
   SaveMail(outlookObject, onlyMails, strUser, strFormat, backupFolderMails, logFolder, bugFolder, indicator)
   System.Runtime.InteropServices.Marshal.FinalReleaseComObject(outlookObject)
   outlookObject = Nothing
   GC.Collect()
   GC.WaitForPendingFinalizers()
   GC.Collect()
   GC.WaitForPendingFinalizers()
Next
以下是“savemail”函数中的代码,该函数保存inlineshape并用文本替换inlineshape:

If GetSeparateAttachments() = True Then
   outlookAllAttachments = outlookObject.Attachments
   attachmentCounter = outlookAllAttachments.Count
   counter = 0
   While attachmentCounter <> counter
      outlookAttachment = outlookAllAttachments(attachmentCounter)
      If outlookAttachment.Type = Outlook.OlAttachmentType.olOLE Then
         If outlookObject.BodyFormat = 3 Then
            outlookInspector = outlookObject.GetInspector
            outlookWordEditor = outlookInspector.WordEditor
            If outlookWordEditor.ProtectionType <> Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection Then
               outlookWordEditor.Unprotect()
            End If
            wordInlineShapes = outlookWordEditor.InlineShapes
            For j As Integer = wordInlineShapes.Count To 1 Step -1
               wordShape = wordInlineShapes.Item(j)
               wordShape.Select()
               outlookWordEditor.Application.Selection.CopyAsPicture()
               dataObject = Clipboard.GetDataObject()
               If dataObject.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
                  image = CType(dataObject.GetData(GetType(System.Drawing.Bitmap)), System.Drawing.Bitmap)
                  secureNameAttachment = CheckPath(GetDuplicateAttachments(), saveFolderAttachment & "\" & CheckFileName(mailTimestamp & "_" & outlookAttachment.DisplayName & j, replaceSign) & GetPictureFormat(image.RawFormat), fileExtension)
                  image.Save(secureNameAttachment)
                  attachmentsString = attachmentsString & ";" & secureNameAttachment
               Else
                  Throw New Exception("Error")
               End If
               wordRange = outlookWordEditor.Range(wordShape.Range.Characters.First.Start, wordShape.Range.Characters.Last.End)
               wordRange.Text = secureNameAttachment & vbCrLf
               System.Runtime.InteropServices.Marshal.FinalReleaseComObject(wordRange)
               wordRange = Nothing
               System.Runtime.InteropServices.Marshal.FinalReleaseComObject(wordShape)
               wordShape = Nothing
               counter = counter + 1
            Next
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(wordInlineShapes)
            wordInlineShapes = Nothing
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(outlookWordEditor)
            outlookWordEditor = Nothing
            outlookInspector.Close(Outlook.OlInspectorClose.olSave)
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(outlookInspector)
            outlookInspector = Nothing
         Else
            Throw New Exception("Error")
         End If
      Else
         '
      End If
      System.Runtime.InteropServices.Marshal.FinalReleaseComObject(outlookAttachment)
      outlookAttachment = Nothing
      System.Runtime.InteropServices.Marshal.FinalReleaseComObject(outlookAllAttachments)
      outlookAllAttachments = Nothing
      outlookObject.Save()
   End While                        
End If
如果GetSeparateAttachments()=True,则
outlookAllAttachments=outlookObject.Attachments
attachmentCounter=outlookAllAttachments.Count
计数器=0
而attachmentCounter计数器
outlookAttachment=outlookAllAttachments(attachmentCounter)
如果outlookAttachment.Type=Outlook.OlAttachmentType.olOLE,则
如果outlookObject.BodyFormat=3,则
outlookInspector=outlookObject.GetInspector
outlookWordEditor=outlookInspector.WordEditor
如果是outlookWordEditor.ProtectionType Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection,则
outlookWordEditor.Unprotect()
如果结束
wordInlineShapes=outlookWordEditor.InlineShapes
对于j作为整数=wordInlineShapes.Count到1步-1
wordShape=wordInlineShapes.Item(j)
wordShape.Select()
outlookWordEditor.Application.Selection.CopyAsPicture()
dataObject=Clipboard.GetDataObject()
如果dataObject.GetDataPresent(GetType(System.Drawing.Bitmap)),则
image=CType(dataObject.GetData(GetType(System.Drawing.Bitmap)),System.Drawing.Bitmap)
secureNameAttachment=CheckPath(GetDuplicateAttachments(),saveFolderAttachment&“\”&CheckFileName(mailTimestamp&“\”&outlookAttachment.DisplayName&j,replaceSign)&GetPictureFormat(image.RawFormat),文件扩展名)
image.Save(secureNameAttachment)
attachmentsString=attachmentsString&“;”&secureNameAttachment
其他的
抛出新异常(“错误”)
如果结束
wordRange=outlookWordEditor.Range(wordShape.Range.Characters.First.Start,wordShape.Range.Characters.Last.End)
wordRange.Text=secureNameAttachment&vbCrLf
System.Runtime.InteropServices.Marshal.FinalEleaseComObject(wordRange)
字范围=无
System.Runtime.InteropServices.Marshal.FinalEleaseComObject(wordShape)
字形=无
计数器=计数器+1
下一个
System.Runtime.InteropServices.Marshal.FinalEleaseComObject(wordInlineShapes)
wordInlineShapes=无
System.Runtime.InteropServices.Marshal.FinalEleaseComObject(outlookWordEditor)
outlookWordEditor=无
outlookInspector.Close(Outlook.OlInspectorClose.olSave)
System.Runtime.InteropServices.Marshal.FinalEleaseComObject(outlookInspector)
outlookInspector=无
其他的
抛出新异常(“错误”)
如果结束
其他的
'
如果结束
System.Runtime.InteropServices.Marshal.FinalEleaseComObject(Outlook附件)
outlookAttachment=Nothing
System.Runtime.InteropServices.Marshal.FinalEleaseComObject(outlookAllAttachments)
outlookAllAttachments=无
outlookObject.Save()
结束时
如果结束

请添加您迄今为止尝试过的内容!源代码这是我目前的代码:休?请编辑您的问题并添加代码。对不起,是我的错,我的位置不对。现在代码在上面。真的,没有人知道吗?任何帮助都将不胜感激。