Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook macro fails... 2

Status
Not open for further replies.

swtrader

IS-IT--Management
Dec 23, 2004
182
US
I copied the following code from vbaexpress.com over a year ago. (Modified it slightly to fit my needs.) It's worked perfectly for over a year. It now fails on the line:

Set mlItm = itm

Possible reason(s)?

Thank you.

===========================================================

'Created by : Charlize
'Revised by : Oorang
' Rewrote a call and jump loop to a Do Until Loop
' Instead of the original if's for the
' attachments, he came up with an array
' of file extensions (pretty slick)
'Rerevised by : Charlize
'Submitted by : Charlize / slight modifications by DRouse
'Date : 2007-10-11 (11 oct 2007)
'Purpose : strip attachments from
' emails to reduce mailbox size
' Save them to a specified folder and
' put a notification in the mail where
' the file was saved to.


Public Sub TestAttachmentRule_Original()
Const lngNoAttchmt_c As Long = 0
Dim Ns As Outlook.NameSpace
Dim mFldr As Outlook.MAPIFolder
Dim itm As Object
Dim mlItm As Outlook.MailItem
Set Ns = Outlook.Application.Session

Set mFldr = Ns.GetDefaultFolder(olFolderInbox)

'List all the file types that you want to save

For Each itm In mFldr.Items
If itm.Class = olMail Then
Set mlItm = itm
If mlItm.Attachments.Count <> lngNoAttchmt_c Then
SaveAttachmentRule mlItm, ".doc", ".xls", ".pdf", ".ppt", ".tif", ".zip"
End If
End If
Next
MsgBox "Files are extracted from" & vbCrLf & _
"the emails in inbox folder.", vbInformation
End Sub
 
Does it fail with an error? If so, could you post it for us please?

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Sorry....guess that would be helpful.

Run-time Error '13'

Type mismatch

 

Why have that variable/statement?
Code:
For Each itm In mFldr.Items
        If itm.Class = olMail Then
            [s]Set mlItm = itm[/s]
            If [b]itm[/b].Attachments.Count <> lngNoAttchmt_c Then
                SaveAttachmentRule mlItm, ".doc", ".xls", ".pdf", ".ppt", ".tif", ".zip"
            End If
        End If
    Next
    MsgBox "Files are extracted from" & vbCrLf & _
    "the emails in inbox folder.", vbInformation
End Sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
What about this ?
Code:
For Each itm In mFldr.Items
  If itm.Class = olMail Then
    If itm.Attachments.Count <> lngNoAttchmt_c Then
      SaveAttachmentRule itm, ".doc", ".xls", ".pdf", ".ppt", ".tif", ".zip"
    End If
  End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I commented out the line that you both recommended I remove. But got another error message deeper into the code. Uncommented the line and ran it again -- without error.

Per MS KB...(
When you programmatically use the Microsoft Outlook object model to open an encrypted e-mail message in Microsoft Office Outlook 2003, the e-mail message does not open. Additionally, you may receive the following error message:
Run-time error '13': Type mismatch

The suggested workaround is a Hotfix -- which I think also requires opening the registry...which begins to get even further afield of my abilities. Won't go there.

My fix...make sure that I'm not trying to save anything that is encrypted. (Not sure that that's the correct workaround -- even for me -- but I am able to downsize my email folder by removing most attachments...so objective is met.)

As always, thanks for your prompt and astute replies. Have no idea how anyone can know as much as you guys know about all of this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top