PC Review


Reply
Thread Tools Rate Thread

Attachments collection bug ?

 
 
chauwel
Guest
Posts: n/a
 
      25th Nov 2009
Outlook 2K3/Exchange

I'm developping a macro to remove all embedded images from my company's mail
templates, but although the templates actually contains images, the
attachments collection remain empty at runtime. And the part that drive me
crazy: in debug mode, the collection is empty (Count=0, etc) until I expand
manually the "attachments" node of my mailitem object in the "Locals" window,
then the collection is populated.

The embbeded images are of type olOLE and there is no other attachment in
the templates. Is that a bug or am i missing something ?
 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      25th Nov 2009
Show the code you use.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"chauwel" <(E-Mail Removed)> wrote in message
news:9A547081-CABD-4989-BC2B-(E-Mail Removed)...
> Outlook 2K3/Exchange
>
> I'm developping a macro to remove all embedded images from my company's
> mail
> templates, but although the templates actually contains images, the
> attachments collection remain empty at runtime. And the part that drive me
> crazy: in debug mode, the collection is empty (Count=0, etc) until I
> expand
> manually the "attachments" node of my mailitem object in the "Locals"
> window,
> then the collection is populated.
>
> The embbeded images are of type olOLE and there is no other attachment in
> the templates. Is that a bug or am i missing something ?


 
Reply With Quote
 
Sue Mosher [MVP]
Guest
Posts: n/a
 
      25th Nov 2009
Also, please explain just what you mean by "mail templates." That could be a
couple of different things in an Outlook context. And it might be helpful to
know why you're doing this -- doesn't that render the templates less
useful? -- and whether Word is your email editor.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Show the code you use.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "chauwel" <(E-Mail Removed)> wrote in message
> news:9A547081-CABD-4989-BC2B-(E-Mail Removed)...
>> Outlook 2K3/Exchange
>>
>> I'm developping a macro to remove all embedded images from my company's
>> mail
>> templates, but although the templates actually contains images, the
>> attachments collection remain empty at runtime. And the part that drive
>> me
>> crazy: in debug mode, the collection is empty (Count=0, etc) until I
>> expand
>> manually the "attachments" node of my mailitem object in the "Locals"
>> window,
>> then the collection is populated.
>>
>> The embbeded images are of type olOLE and there is no other attachment in
>> the templates. Is that a bug or am i missing something ?

>



 
Reply With Quote
 
chauwel
Guest
Posts: n/a
 
      25th Nov 2009
The email editor is Word 2003.
The company is undergoing a rebranding, so the logos and so on must be
removed (ideally replaced) and there is over 600 hundred .oft files to
process.

Public Sub Macro_RemoveImages()
Const PICTURE_TAG = "PICTURE (METAFILE)"
Dim olApp As New Outlook.Application

Dim mail As MailItem
Dim sourcePath As String
Dim targetPath As String

sourcePath = OpenFolderDialog(TEMPLATE_FOLDER, "Source folder:")
If sourcePath = "" Then Exit Sub

targetPath = OpenFolderDialog(TEMPLATE_FOLDER, "Target folder:")
If targetPath = "" Then Exit Sub

If UCase(targetPath) = UCase(sourcePath) Then
MsgBox "Source path and Target must be different", vbExclamation
Exit Sub
End If

Dim fso As Object, ofile As Object, folder As Object
Set fso = CreateFileSystemObject()

Dim i As Integer, c As Integer, savePath As String
Dim att As Attachment, atts() As Attachment
Set folder = fso.GetFolder(sourcePath)

For Each ofile In folder.Files
Debug.Print "*****************************"
Debug.Print "Loading " & ofile.name
Debug.Print "*****************************"

savePath = targetPath & "\" & ofile.name
Set mail = olApp.CreateItemFromTemplate(sourcePath & "\" & ofile.name)

If mail.Attachments.Count > 0 Then '<= Fails here
c = mail.Attachments.Count
ReDim atts(1 To c)

For i = 1 To c
Set att = mail.Attachments(i)
Debug.Print vbTab & "DisplayName: " & att.DisplayName
Debug.Print vbTab & "Type: " & att.Type
Debug.Print vbTab & "Position: " & att.Position
Debug.Print vbTab & "Index: " & att.Index
Debug.Print "---------------------------"
Set atts(i) = att
Next

For i = 1 To c
Set att = atts(i)
If UCase(att.DisplayName) = PICTURE_TAG Then
att.Delete
Debug.Print "Removed: " & i
End If
Next
End If

Debug.Print "Saving As " & savePath
mail.SaveAs savePath, OlSaveAsType.olTemplate
Set mail = Nothing
Next
End Sub


"Sue Mosher [MVP]" wrote:

> Also, please explain just what you mean by "mail templates." That could be a
> couple of different things in an Outlook context. And it might be helpful to
> know why you're doing this -- doesn't that render the templates less
> useful? -- and whether Word is your email editor.
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook 2007 Programming:
> Jumpstart for Power Users and Administrators
> http://www.outlookcode.com/article.aspx?id=54
>
>
> "Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Show the code you use.
> >
> > --
> > Ken Slovak
> > [MVP - Outlook]
> > http://www.slovaktech.com
> > Author: Professional Programming Outlook 2007.
> > Reminder Manager, Extended Reminders, Attachment Options.
> > http://www.slovaktech.com/products.htm
> >
> >
> > "chauwel" <(E-Mail Removed)> wrote in message
> > news:9A547081-CABD-4989-BC2B-(E-Mail Removed)...
> >> Outlook 2K3/Exchange
> >>
> >> I'm developping a macro to remove all embedded images from my company's
> >> mail
> >> templates, but although the templates actually contains images, the
> >> attachments collection remain empty at runtime. And the part that drive
> >> me
> >> crazy: in debug mode, the collection is empty (Count=0, etc) until I
> >> expand
> >> manually the "attachments" node of my mailitem object in the "Locals"
> >> window,
> >> then the collection is populated.
> >>
> >> The embbeded images are of type olOLE and there is no other attachment in
> >> the templates. Is that a bug or am i missing something ?

> >

>
>
> .
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      25th Nov 2009
I have no idea why it's failing on this line:

If mail.Attachments.Count > 0 Then '<= Fails here

However, try instantiating an Attachments collection first:

Dim colAttach As Outlook.Attachments
Set colAttach = mail.Attachments
c = colAttach.Count
If c > 0 Then

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"chauwel" <(E-Mail Removed)> wrote in message
news:4C033B21-64A2-4167-BB21-(E-Mail Removed)...
> The email editor is Word 2003.
> The company is undergoing a rebranding, so the logos and so on must be
> removed (ideally replaced) and there is over 600 hundred .oft files to
> process.
>
> Public Sub Macro_RemoveImages()
> Const PICTURE_TAG = "PICTURE (METAFILE)"
> Dim olApp As New Outlook.Application
>
> Dim mail As MailItem
> Dim sourcePath As String
> Dim targetPath As String
>
> sourcePath = OpenFolderDialog(TEMPLATE_FOLDER, "Source folder:")
> If sourcePath = "" Then Exit Sub
>
> targetPath = OpenFolderDialog(TEMPLATE_FOLDER, "Target folder:")
> If targetPath = "" Then Exit Sub
>
> If UCase(targetPath) = UCase(sourcePath) Then
> MsgBox "Source path and Target must be different", vbExclamation
> Exit Sub
> End If
>
> Dim fso As Object, ofile As Object, folder As Object
> Set fso = CreateFileSystemObject()
>
> Dim i As Integer, c As Integer, savePath As String
> Dim att As Attachment, atts() As Attachment
> Set folder = fso.GetFolder(sourcePath)
>
> For Each ofile In folder.Files
> Debug.Print "*****************************"
> Debug.Print "Loading " & ofile.name
> Debug.Print "*****************************"
>
> savePath = targetPath & "\" & ofile.name
> Set mail = olApp.CreateItemFromTemplate(sourcePath & "\" &
> ofile.name)
>
> If mail.Attachments.Count > 0 Then '<= Fails here
> c = mail.Attachments.Count
> ReDim atts(1 To c)
>
> For i = 1 To c
> Set att = mail.Attachments(i)
> Debug.Print vbTab & "DisplayName: " & att.DisplayName
> Debug.Print vbTab & "Type: " & att.Type
> Debug.Print vbTab & "Position: " & att.Position
> Debug.Print vbTab & "Index: " & att.Index
> Debug.Print "---------------------------"
> Set atts(i) = att
> Next
>
> For i = 1 To c
> Set att = atts(i)
> If UCase(att.DisplayName) = PICTURE_TAG Then
> att.Delete
> Debug.Print "Removed: " & i
> End If
> Next
> End If
>
> Debug.Print "Saving As " & savePath
> mail.SaveAs savePath, OlSaveAsType.olTemplate
> Set mail = Nothing
> Next
> End Sub


 
Reply With Quote
 
Sue Mosher [MVP]
Guest
Posts: n/a
 
      25th Nov 2009
That does seem odd. You might want to try saving the item before attempting
to access its Attachments collection.

Alternatively, go through Inspector.WordEditor to work with the
Word.Document that forms the body of the message.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"chauwel" <(E-Mail Removed)> wrote in message
news:4C033B21-64A2-4167-BB21-(E-Mail Removed)...
> The email editor is Word 2003.
> The company is undergoing a rebranding, so the logos and so on must be
> removed (ideally replaced) and there is over 600 hundred .oft files to
> process.
>
> Public Sub Macro_RemoveImages()
> Const PICTURE_TAG = "PICTURE (METAFILE)"
> Dim olApp As New Outlook.Application
>
> Dim mail As MailItem
> Dim sourcePath As String
> Dim targetPath As String
>
> sourcePath = OpenFolderDialog(TEMPLATE_FOLDER, "Source folder:")
> If sourcePath = "" Then Exit Sub
>
> targetPath = OpenFolderDialog(TEMPLATE_FOLDER, "Target folder:")
> If targetPath = "" Then Exit Sub
>
> If UCase(targetPath) = UCase(sourcePath) Then
> MsgBox "Source path and Target must be different", vbExclamation
> Exit Sub
> End If
>
> Dim fso As Object, ofile As Object, folder As Object
> Set fso = CreateFileSystemObject()
>
> Dim i As Integer, c As Integer, savePath As String
> Dim att As Attachment, atts() As Attachment
> Set folder = fso.GetFolder(sourcePath)
>
> For Each ofile In folder.Files
> Debug.Print "*****************************"
> Debug.Print "Loading " & ofile.name
> Debug.Print "*****************************"
>
> savePath = targetPath & "\" & ofile.name
> Set mail = olApp.CreateItemFromTemplate(sourcePath & "\" &
> ofile.name)
>
> If mail.Attachments.Count > 0 Then '<= Fails here
> c = mail.Attachments.Count
> ReDim atts(1 To c)
>
> For i = 1 To c
> Set att = mail.Attachments(i)
> Debug.Print vbTab & "DisplayName: " & att.DisplayName
> Debug.Print vbTab & "Type: " & att.Type
> Debug.Print vbTab & "Position: " & att.Position
> Debug.Print vbTab & "Index: " & att.Index
> Debug.Print "---------------------------"
> Set atts(i) = att
> Next
>
> For i = 1 To c
> Set att = atts(i)
> If UCase(att.DisplayName) = PICTURE_TAG Then
> att.Delete
> Debug.Print "Removed: " & i
> End If
> Next
> End If
>
> Debug.Print "Saving As " & savePath
> mail.SaveAs savePath, OlSaveAsType.olTemplate
> Set mail = Nothing
> Next
> End Sub
>
>
> "Sue Mosher [MVP]" wrote:
>
>> Also, please explain just what you mean by "mail templates." That could
>> be a
>> couple of different things in an Outlook context. And it might be helpful
>> to
>> know why you're doing this -- doesn't that render the templates less
>> useful? -- and whether Word is your email editor.
>> --
>> Sue Mosher, Outlook MVP
>> Author of Microsoft Outlook 2007 Programming:
>> Jumpstart for Power Users and Administrators
>> http://www.outlookcode.com/article.aspx?id=54
>>
>>
>> "Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>> > Show the code you use.
>> >
>> > --
>> > Ken Slovak
>> > [MVP - Outlook]
>> > http://www.slovaktech.com
>> > Author: Professional Programming Outlook 2007.
>> > Reminder Manager, Extended Reminders, Attachment Options.
>> > http://www.slovaktech.com/products.htm
>> >
>> >
>> > "chauwel" <(E-Mail Removed)> wrote in message
>> > news:9A547081-CABD-4989-BC2B-(E-Mail Removed)...
>> >> Outlook 2K3/Exchange
>> >>
>> >> I'm developping a macro to remove all embedded images from my
>> >> company's
>> >> mail
>> >> templates, but although the templates actually contains images, the
>> >> attachments collection remain empty at runtime. And the part that
>> >> drive
>> >> me
>> >> crazy: in debug mode, the collection is empty (Count=0, etc) until I
>> >> expand
>> >> manually the "attachments" node of my mailitem object in the "Locals"
>> >> window,
>> >> then the collection is populated.
>> >>
>> >> The embbeded images are of type olOLE and there is no other attachment
>> >> in
>> >> the templates. Is that a bug or am i missing something ?



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Iterate through collection of attachments PromisedOyster Microsoft Outlook VBA Programming 3 22nd Jan 2010 02:19 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
Can't get collection to save when using collection of custom class as property of control in VS 2005 J.Edwards Microsoft Dot NET Compact Framework 0 10th Jan 2006 04:44 AM
key/value collection that allows key string to be updated and retains collection item entry order dx Microsoft Dot NET Framework 2 25th Sep 2004 05:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:51 PM.