Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

How Do I Read An Outlook .msg File And Its Attachments?

How do I read an outlook .msg file, and extract all the neccessary information from it. And also get the list of file attachments stored in the file?


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Read MS Outlook Attachments
Dear gurus
how to read the attachments in MS Outlook thro' vb. The attachments are
.msg files.
Is there any method to read it without saving it to the ground ?

Best Regards,

Outlook. How Do I Read The Contents Of Attachments That Are Emails?

We need to process emails that have been returned undeliverable to an Outlook folder.

We store a tag in the original email body with an ID I need.

Some returned emails contain the original message in the email body and stepping through a list of emails and processing the bodies to find the tag is easy enough.

However, in a majority of the returns the original email is an attachment containing the original email (.msg format).

Can anyone one help me work out how to open and scan the contents of that attachment?

I'm working in VB6 and the target Outlook will probably be a fairly recent one (certainly at least from Office 2000)


Attachments To File And Outlook Automation
hi, i've been searching through the forums for days now trying to solve this problem.

i want to detect receipt of an email and extract an attachment from outlook upon its arrival. once the attachment is copied to a directory i want to execute a command to start a vb script. i am fairly certain i have a grasp on getting the vb script to trigger once the files appear in the directory. what i have been unable to do is get the attachment to auto detach into a directory. i've tried to use rules in outlook to detect the email arrival, and then trigger a script execute another script in access to execute the detachment of the attachment, but i keep getting errors such as "the expression you entered has a function name that Microsoft Access can't find"

i'm sure that my code has become convoluted and way more complex than it has to be. if anyone can suggest a simpler way to do this i'd be happy enough to pee myself. i'd post my code, but frankly it's embarassing and i'd like to look at this from a totally fresh perspective rather than try to patch what i've written so far.

Outlook 2000 File Attachments
Can any one tell me how to write a vb exe so when I send the exe as a file attachment it is automatically saved to the recipients hard drive. My office users often times forget to and they loose the attachment.

Using The OLEDragDrop Event With Outlook File Attachments
I developed a GUI in VB 6 that uses OLE dragdrop to process files dropped from Explorer. Sometimes these files arrive via email and I would like to be able to drag the files out of an an open Outlook email message window and drop them into a control on my application.

When the drop event fires, I need to access the name(s) of the attached file(s) and the binary contents of the file(s).
External dlls / components are generally frowned upon by my company. I need a pure VB (APIs allowed) solution. I would also prefer not to use Outlook Automation components. I especially would like to avoid solutions involving the subclassing dll that's commonly used as this would not be acceptable by my company's standards.

I've read several posts about this on various forums ranging from "just use the DataObject's files collection" to "use this component developed in C++" which doesn't look like anything I couldn't just do in VB, yet it doesn't work. The File List format that would normally have a list of files when copying/draging from Explorer is not available for Outlook attachments.

I've learned that the clipboard formats available for an OLE object sitting on the clipboard are similar to the formats available during an OLEDragDrop event, but not all of the same formats are available. Using enumeration APIs, I found the following formats available for an Outlook file attachment in the clipboard:DataObject
Embedded Object
Object Descriptor
Meta-File Picture
Rich Text Format
RichEdit Binary
Rich Text Format Without Objects
Ole Private Data
Enhanced Meta-File Picture
FileGroupDescriptor and FileContents are all I need to grab and they work fine for reading off the clipboard (some simple API calls needed). During the OLEDragDrop event the FileGroupDescriptor format gets me the file name, but the FileContents format is reported as unavailable. I don't know if there's some way to tell something to make it available by setting something on the drop destination control or calling some api during the drop event but I can't find anything.

As a possible alternative, I did find that the Rich Text Format property is readable. When I looked at the ObjectData I saw hexadecimal numbers representing the actual object data. Converting them to binary, I see "Outlook.FileAttach" as an object class name, some other random data resembling an object header and somewhere in there is the actual binary contents of the file. If I could get some specs on this RTF format that the Outlook attachment is stored in, I believe I could simply extract the file from there.

Does anyone have any knowledge about this?


Multiple Attachments In Outlook Express Versus Outlook

I have a piece of code that takes files from a MS Access database and saves documents to an exterior location, then attaches those documents to an email in compose mode so that the user can add recipients. THe user is selecting the documents they want to add from a grid.  This code works flawlessly when Outlook Express is the default mail client.  However, when Outlook is the default mail client, the code pretty much stops after adding the attachments to the external directory and never composes.  Do I have to rewrite this for outlook or is there something missing?

Thanks for anyone whom can help me. I have scoured endlessly on the net to find out what the differences are between Outlook express and outlook to get some resolution and nothing can be found.


Private Sub SendMultipleMSDSs()
    Dim blnMultMsds As Boolean
    Dim intCount As Integer
    Dim intTotRecs As Integer
    Dim strSourceId As String
    Dim strEffdate As String
    Dim strCustNum As String
    Dim sProdName As String
    Dim strIsAre As String
    Dim ssQL As String
    Dim arecPrint As New ADODB.Recordset
    Dim intRet As Integer
    Dim Msg As String
    Dim strFile As String
    Dim intI As Integer
    Dim intRecip As Integer
    Dim sESubject As String
    Dim sEbody As String
    Dim sFile As String
    Dim strFPath As String
    Dim sFileDir As String
    Dim NoofMsds As Integer
    Dim vntSourceid
    Dim vntEffdate
    Dim vntProdName
    Dim intRet1 As Integer
    On Error GoTo errPrintMultiple
    MkDir App.Path & "email"
    If clsGlobalObj.FileExists(App.Path & "email*.*") Then
            Kill App.Path & "email*.*"
    End If
    If Me.MAPISessionMain.SessionID = 0 Then          Me.MAPISessionMain.SignOn
    End If
    NoofMsds = 0
    For intCount = 1 To Me.grdMain.MaxRows
        Me.grdMain.Row = intCount
        Me.grdMain.Col = 1
        If Me.grdMain.Value = 1 Then
            NoofMsds = NoofMsds + 1
        End If
    If NoofMsds = 0 Then
       MsgBox "There are no MSDSs to send", vbExclamation, "Email Multiple MSDSs"
       Exit Sub
    End If
    strIsAre = "are "
    If NoofMsds = 1 Then
      strIsAre = "is "
    End If

    If MsgBox("There " + strIsAre + Trim(str(NoofMsds)) + " MSDSs to Send" + Chr(13) + Chr(10) + "          Are You Sure?", vbYesNo + vbQuestion, "Send Multiple MSDSs") = 7 Then
       Screen.MousePointer = vbDefault
       Exit Sub
    End If
    NoofMsds = 0
    sESubject = GetSetting(gsAPP_TITLE, "Options", "ESubject", "Requested MSDS")
    sEbody = GetSetting(gsAPP_TITLE, "Options", "EBody", "Please Find the attached MSDS document")
    Me.MAPIMsgMain.SessionID = Me.MAPISessionMain.SessionID
    Me.MAPIMsgMain.MsgSubject = sESubject
    Me.MAPIMsgMain.MsgNoteText = sEbody
    For intCount = 1 To Me.grdMain.MaxRows
            Me.grdMain.Row = intCount
            Me.grdMain.Col = 1
            If Me.grdMain.Value = 1 Then
                NoofMsds = NoofMsds + 1
                intRet1 = Me.grdMain.GetText(2, intCount, vntProdName)
                intRet1 = Me.grdMain.GetText(4, intCount, vntEffdate)
                intRet1 = Me.grdMain.GetText(5, intCount, vntSourceid)
                'added condition delete=true 2/13/02
                strSourceId = vntSourceid
                strEffdate = vntEffdate
                sProdName = clsGlobalObj.CheckSQL(CStr(vntProdName), SQL_IN)
                If InStr(1, Trim(sProdName), "/") > 0 Then sProdName = Mid(Trim(sProdName), 2, InStr(1, Trim(sProdName), "/") - 2)
                If InStr(1, Trim(sProdName), "") > 0 Then sProdName = Mid(Trim(sProdName), 2, InStr(1, Trim(sProdName), "") - 2)
                sProdName = IIf(InStr(1, Trim(sProdName), "#"), Replace(Trim(sProdName), "#", "0"), sProdName)
                If arecTemp.State = 1 Then arecTemp.Close
                gstrSql = "SELECT body_type,msdsbody,tagnum FROM msds_bod "
                gstrSql = gstrSql & "Where  sourceid='" & strSourceId & "' and effdate = #" & strEffdate & "# "
                clsGetData.GetSQLResults gstrSql, arecTemp, aconMain, adOpenStatic, adLockOptimistic
                If Not (arecTemp.EOF And arecTemp.BOF) Then
                 'assure that msdsbody value is not null
                    If Not IsNull(arecTemp.Fields(1)) Then
                       If Trim(arecTemp.Fields(1)) <> "" Then
                           strFile = App.Path & "email" & Trim(sProdName) & "." & Trim(arecTemp.Fields(0))
                           If arecTemp1.State = 1 Then arecTemp1.Close
                           strFile = SendScans(strSourceId, strEffdate)
                       End If
                       If arecTemp1.State = 1 Then arecTemp1.Close
                       strFile = SendScans(strSourceId, strEffdate)
                    End If
                    MsgBox "There is no MSDS Body or Scannned image to attach.", vbOKOnly, gsAPP_TITLE
                    Exit Sub
                End If
                If arecTemp.State = 1 Then arecTemp.Close
                'if body exists
                If UCase(Right(Trim(strFile), 3)) = "HTM" Or UCase(Right(Trim(strFile), 4)) = "HTML" Or UCase(Right(Trim(strFile), 4)) = "SGML" Or UCase(Right(Trim(strFile), 3)) = "TXT" Then
                    If clsGlobalObj.FileExists(strFile) Then
                        Screen.MousePointer = Default
                        Kill strFile
                    End If
                    ExportHTML strFile, strSourceId, strEffdate
                Else 'if image exists
                End If
                    Me.MAPIMsgMain.AttachmentPathName = Trim(strFile)
                    If UCase(Right(Trim(strFile), 3)) = "PDF" Or UCase(Right(Trim(strFile), 3)) = "TIF" Or UCase(Right(Trim(strFile), 3)) = "GIF" Then
                        Me.MAPIMsgMain.AttachmentName = Trim(sProdName) & "." & UCase(Right(Trim(strFile), 3))
                    ElseIf UCase(Right(Trim(strFile), 4)) = "TIFF" Then
                        Me.MAPIMsgMain.AttachmentName = Trim(sProdName) & ".TIFF"
                    End If
                Me.MAPIMsgMain.AttachmentIndex = NoofMsds
            End If

    If Trim(strFile) = "" Then
       MsgBox "No attachment to send.", vbInformation, gsAPP_TITLE
       Exit Sub
    End If
    Me.MAPIMsgMain.Send True
    For intCount = 1 To 2000

    gblnPOPMSDS = True
    Exit Sub
'*********** Error Handler *******************************
    If Err.Number = 75 Then
        Resume Next
    ElseIf Err.Number = 32001 Then
        Exit Sub
    ElseIf Err.Number = 48389 Then
        MsgBox "Please install Microsoft outlook on your machine to use Emailing attachment.", vbInformation + vbOKOnly, gsAPP_TITLE
        Exit Sub
    ElseIf Err.Number = 32056 Then
        Resume Next
    ElseIf ErrorHandler("MnuPOPsendMSDS", Err) = ERR_RETRY Then
    End If
  Exit Sub

    '-- Cleanup
    If arecPrint.State = 1 Then arecPrint.Close
    frmMain.Enabled = True
    If Err.Number = 55 Then
       Resume Next
    ElseIf Err.Number = 75 Then 'added on 6/18/04
        Resume Next
    ElseIf Err.Number = 32001 Then
        Exit Sub
    ElseIf Err.Number = 48389 Then
        MsgBox "Please install Microsoft outlook on your machine to use Emailing attachment.", vbInformation + vbOKOnly, gsAPP_TITLE
        Exit Sub
    ElseIf Err.Number = 32056 Then
        Resume Next

    End If
End Sub

Get Body And Attachments Of Outlook Msg WITHOUT Outlook??
I'm trying to find a way in VB6 to extract the attachment(s) and body of an Outlook .msg file WITHOUT using the Outlook object.

Does anyone know how to do this?

I found some code, but it doesn't work - perhaps someone else can troubleshoot it or point me in the right direction?

How To Read Outlook's .pst File
Hi Friends

In the project which i am working i need to open outlook's .pst file and read the mails one by one. Can any one help me on this. Thanks in advance

VB &lt;&gt; Outlook Attachments
Dear all,

The following code is an example to get the attachments(from oulook mail) and save this into a directory
from an visual basic application. I have a question and hope somebody could give a solution.
For example i have created a folder in outlook like "Processed". Is it possible when i
extract the attachments(from the inbox folder) and then move this mail into the folder "processed".
So can i keep my inbox clearly and can i know what i have extracted.

Thanks in advance.


Private Sub Command1_Click()

On Error Resume Next

Me.lblopgeslagen.Caption = ""
Me.lstStatus.Enabled = True

Dim oApp As Outlook.Application
Dim oNameSpace As NameSpace
Dim oFolder As MAPIFolder
Dim oMailItem As Object
Dim sMessage As String

Set oApp = New Outlook.Application
Set oNameSpace = oApp.GetNamespace("MAPI")

Set oFolder = oNameSpace.PickFolder

Dim count As Integer
Me.Command1.Enabled = False
For Each oMailItem In oFolder.Items
With oMailItem
If oMailItem.Attachments.Count > 0 Then
oMailItem.Attachments.Item(1).SaveAsFile Dir1.Path & "" & _
oMailItem.Attachments.Item(1).Parent & "ORDERIN-" & _
lstStatus.AddItem (oMailItem.Attachments.Item(1).FileName)
count = count + 1
lblopgeslagen.Caption = count & " Opgeslagen"

End If
End With
Next oMailItem

Set oMailItem = Nothing
Set oFolder = Nothing
Set oNameSpace = Nothing
Set oApp = Nothing

Me.Command1.Enabled = True
End Sub

Outlook Attachments
Howdy VB'ers,

I am trying to play with attachments pulled out from Outlook mailitems but cant seem to reference them correctly.

Dim ScaryAttachment As Attachment

Set ScaryAttachment = moInbox.Items(int_loop).Attachments(1)

All this does is set ScaryAttachment to the name of the attachment rather than the actual object itself.

Any ideas?

Outlook Attachments
Hi, I have managed to be able to send out a file through excel, but how can I actually attach a or the spreadsheet in Outlook



Outlook Attachments
I have never worked with VB in outlook before and just need some help with the following.

I need it to auto save all attachments in all incoming mail to a folder.

Just the attachment. eg if a photo was saved as an attachment to would save just the photo to a specific folder.

Thanks for any help.

Attachments In Outlook
gd morning

normally i use outlook express for mail purposes.
when i used outlook instead, the attachment function did not work, at least when i tried to attach more that 1.
does .attachmentindex not work with outlook?
or how can i overcome this error?


&lt;?&gt; Outlook...Attachments
Sending emails...jFound the problem I was having getting it to work on NT

'this works
With objOutlookMsg
.To = Rst!email
.Subject = mySubject
.Body = "To All Parties Concerned:" & vbNewLine & vbNewLine
.Importance = olImportanceHigh
'***.what code adds an attachment in the form of a file.***
End With

What I require is the line of code or other to add an
attachment to the email. Anyone have this handy.

Outlook Attachments
I need to send an email in VB that looks like this:

This is some of the body


Some more of the body

another attachment

I tried using Mapi Position property, but I use outlook 2000 and its puts the attachments at the end of the email no matter what. So now I'm trying to use the Outlook stuff. Can anyone help me?


CDO Attachments In Outlook
I get a wierd error for the following code:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim objAttach As CDO.Message
Set objAttach = .Attachments.Add
With objAttach
.Type = CdoFileData
.Position = 0 ' render at first character of message
.Name = "c:objectattachment.txt"
.ReadFromFile "c:objectattachment.txt"
End With
objAttach.Name = "attachment.txt"

End Sub


Compile Error:

Invalid or Unqualified reference


I am running Outlook 2000 SP1 on Windows 2000 with CDO Lib 1.21 and CDONTS as well. I do have these references selected in my application. What else could be the problem?

Timothy H. Schilbach
Alpha Omega Design Inc.

Outlook Attachments
I'm using shellexecute as a mailto: link on a VB Form..

how do i send a log.txt as an attachment right away.

Attachments With Outlook

I need to send an embedded Word attachment in Outlook and this from my vb-application.

I know how to send the word doc as an attachment
but only as icon on the bottom.
What I want is to send this attachment but embedded in the mailitem.

Something like
mailitem.body = worddoc.activedocument

I know you can do this in the outlook program,
but who knows how to do this through the object model ????

Read From XML File In Outlook Macro

Can annybody explain me how to read from a xml file in VBA.
I have a XML file that i want to import to and outlook adres book.



Read Attachments Using MAPI
I need to read an attachment that gets created from a bounced email message--one that has no recipient.

Adding Attachments To Outlook
Ok, so after alot of headache (and some re-eduction) I finally got a script to work that allows you to attach a document to an Email. Only issue is, I dont want it to open a new email to attach said email anymore. I usually Frankenstien my code togeather, and the lines that are part of the "Open a new email" section are tighed in to the "Attach the file" portion. I tried a Set TargetDoc = ActiveWindow approch, but no real luck. Can anyone help me, my brain is fried and I could use a fresh pair of eyes.

Sub Test1()

Set FindOutlook = CreateObject("Outlook.Application")
Set MakeMessage = FindOutlook.CreateItem(0)

MakeMessage.Attachments.Add "c: estfile.txt"

End Sub

Also, I will have to have this working for not only Outlook 2k-2k3, but also 2k7. Havent tested it yet, but I will shortly. If anyone happens to see anything that might cause an issue or hick-up that can point it out, that would be great, but I think I can figure it out tomorrow, I am just drained at this point.

How Do I Grab MS Outlook Attachments?
Hi im new here, just need this for my project, really need your help guys

how do i grab attachments from MS outlook coming from a particular person then save into a particular directory in my pc using VB6?thank you so much

Outlook Multiple Attachments
Hi guys...

Im trying this but no joy

It fails as the path is not valid.
i.e. it gives me - which i know is wrong but how should it be
(from my debug print)

"\serverDataDevelop estpath.txt;C:Program FilesMicrosoft Visual Studiola estfile.EXE;"

i want to be able to select the items in my list view and email all my selected ones as attachments.#

i call it here

Dim DocumentLocations As String
Dim e As Integer

DocumentLocations = ""

For e = 1 To ListViewcF.ListItems.Count

If ListViewcF.ListItems(e).Selected Then
DocumentLocations = ListViewcF.ListItems(e).SubItems(1) & ";" & DocumentLocations
End If


' email the documents which are in the list and selected
SendOutLookMailwithAttach Me.txtxEmail, "", "", DocumentLocations

in my main module

Sub SendOutLookMailwithAttach(txtTo As String, txtSubject As String, txtBody As String, docLoc As String)

Dim oApp As Object
Dim oEmail As Object
Dim amp As String
amp = """"

Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(olMailItem)

With oEmail
.To = txtTo

.Subject = txtSubject

.Body = txtBody
.Importance = olImportanceHigh

Debug.Print amp & docLoc & amp
.Attachments.Add docLoc, olByValue

.Display 'Show the email message and allow for editing before sending

End With

End Sub

Outlook - Save Jpg Attachments
G'Day all,

I have a routine that successfully iterates one of my Outlook folders.

This folder has attachments, and I can use the .SaveAs to save the attachments. Problem is that object.SaveAs(Path, [Type]) dosn't support saving .jpgs etc.

So my question is how can I save images?

One for you RobDog


How Can You Add Attachments To Outlook Express With VB?
im using the code

Dim objOutlook As New Outlook.Application
Dim objOutlookMsg As Outlook.MailItem

' Create New message
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
.To = Text3.Text
.Subject = "Report"
.Body = "Attachment included"
.Importance = olImportanceHigh

End With

how can i add an attachment?

Outlook - Strip Out Attachments

I've seen an example in here listing the code to go through your inbox and save away the attachments from any e-mails that have attachments.

If the search was working I'd use it, but does anyone have the code?


Know the thread?


Printing Outlook Attachments

My first time posting here. I dont know where to post this, so the Newbie area seemed like the best idea.

I have a VB app that I would like to connect to my Outlook, check a specific folder, and if it finds any attachments in a certain folder, on a message that is still unread, print it. I got this far :
Public Function printAttachments(ByVal scheme As String) 'where scheme is the folder name
    On Error GoTo ErrHandler

    Dim teller As Integer
    Set oOutlook = New Outlook.Application
    Set oNs = oOutlook.GetNamespace("MAPI")
    If gotoFolder(scheme) Then    'moves the the selected folder
        For Each oMessage In oFldr.Items
            If oMessage.Attachments.Count > 0 And oMessage.UnRead Then
                For teller = 1 To oMessage.Attachments.Count
                    oMessage.Attachments.Item(teller).Print    'this is the problem area, it calls a 'Object doesn't support this property or method' error', as I do not know which proc to call here...
                Next teller
            End If
        Next oMessage
        MsgBox "Unable to find " & scheme
    MsgBox Error
    Set oMessage = Nothing
    Set oFldr = Nothing
    Set oNs = Nothing
    Set oOutlook = Nothing
    End If
End Function

Any help would be appreciated

Open Outlook Attachments

I really don't know where to start on this, as I only have Excel/Access VBA knowledge, and would therefore really appreciate any help!

I would like to write some code that for an e-mail that I have selected (highlighted) in MS Outlook to open the attachement (will be either .pdf or .fax files (Adobe Acrobat or Faxmaker Fax Viewer)) and print it out, then close the attachement. If it is possible to mark the fax as viewed as well, then this would be beneficial.

I am aware that this has some security issues, but we have some fairly comprehensive Anti-virus software here, and this would be really beneficial.

Ultimately I would like to attach this to a button, and roll it out to other users.

Kind regards in advance


Saving Attachments In Outlook

I found code to save Outlook attachments here. This code saves attachments from the default Inbox. How can I change this to save attachments from any of the folders i created myself?

Thanks very much,


Outlook Attachments Object
I should be grateful if anyone could help with the following problem:

In my Outlook Add-in program, Iím using the Attachments object Count property to get the number of attachments in e-mails. The problem is that items that are not attached documents are included.

For example, the Attachments object returns items such as logo.gif and submit.gif that are in Newsletter e-mails when there is no actual document attached.

How do I know actual documents attached from those that are not?

Many thanks.

Saving Attachments In Outlook 2003
I have a piece of code that I worked out from some help here and a bit on my own and it worked great for saving the pdf attachment out of my emails to a folder. We had Office 2002 and have now installed Office 2003 here at work and I now get an error. The code it as follows.

Sub move()
Set myolapp = CreateObject("Outlook.Application")
Set myNameSpace = myolapp.GetNamespace("MAPI")
Set myinbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myFolder = myinbox.Folders("POS")
Set myItems = myFolder.Items
Set myDestFolder = myinbox.Folders("Processed")
Set myItem = myItems.Find("[attachment] = '.xls'")
While TypeName(myItem) <> "Nothing"
myItem.Attachments(1).SaveAsFile "C:my folderpos" & myItem.Subject & ".pdf"
myItem.move myDestFolder
Set myItem = myItems.FindNext
End Sub
The error comes on the line
Set myItem = myItems.Find("[attachment] = '.xls'")
The error I get if it helps which I am thinking it won't is
run-time error '-2147352567 (800200009)

Condition is not valid.

I thought that it would be the references and maybe it is. I don't do alot of work with VBA so i'm not sure. I have Visual basic for applications, Microsoft outlook 11.0 object library, ole automation, and Microsoft outlook 10.0 object library all checked.

Please help and hate saving my purchase orders manually!!!

Outlook Attachments And Long FileNames
I am writing a small program that takes a file name via the command line, creates and email and attaches the file to the email. The problem is that if the file name has spaces Outlook doesn't like the name. I have tried using GetShortPathName and the FileSystemObject to get the 8.3 file name. In debug mode this works fine but when I make a compiled exe it doesn't work!


Outlook: Delete All Attachments From Every Items
delete all items:

Set TestItems = TestFolder.Items
For Each Itm In TestItems

everything is work, but next code is wrong. I can't understand why:

Set TestItems = olNewFolder.Items
For Each Itm In TestItems
Set myAtt = Itm.Attachments
If myAtt.Count > 0 Then
myAttCount = myAtt.Count
If myAttCount = 0 Then Exit Do
For Each b In myAtt
Next b
myAttCount = myAttCount - 1
End If
Next Itm

Printing Out Outlook Word Attachments

i have the following problem. I want to code an VBA Macro which should print out the word attachments from a specific sender. (only inbox, not subfolders). I have the following code which does not work. The error message is: Runtime error 5174. The file could not found.

Sub test()

Dim strNewFolder As String
Dim objPosteingang As MAPIFolder
Dim objNewMail As MailItem

Dim wrdApp As Object
Dim wrdDoc As Object
Dim Datei As String

'On Error Resume Next

Set objPosteingang = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
For Each objNewMail In objPosteingang.Items
If objNewMail.SenderName = "Testuser" Then
intAnlagen = objNewMail.Attachments.Count
If intAnlagen > 0 Then
For i = 1 To intAnlagen
Set wrdApp = CreateObject("Word.Application")
Datei = objNewMail.Attachments.Item(i).FileName
Set wrdDoc = wrdApp.Documents.Open(Datei)
Application.Wait Now + TimeSerial(0, 0, 10)
Next i
End If
End If
Next objNewMail

End Sub

My Problem ist that i can't save the attachment before, because this should be work if the pc is turned off, too!

Thanks for your help!!

Detach Attachments And Save In Outlook

any ideas/pointers to code that is capable of trawling thru my Outlook inbox and detaching attachments into a specified directory? Of course it needs to take care of situations where an email has no attachments or multiple attachments ... and of course the situation where a file about to be saved may already exist.


Outlook Attachments...(adding Text)
I have created an email... added all to, cc, etc..

but what I need to do is insert text between attachemnts!

text1 saying whatever...

Attachment 1 Attchment 2

text2 saying...

Attcahment 3 Att4 att5


How do I "split" the body up to do this?


Unblocking Outlook Express Attachments.
Sorry guys, I know this isn't really a VB questions, but I figured if anyone would know how to help it'd be you guys! I'm almost certainly not the only one that needs help with this!

Since getting Outlook Express 6 security updates, I can't open various email attachments that it'd be good to be able to open! (Like mpeg, for instance.) I believe there's a way of manually overriding which file types are blocked by editing the registry, but I can't find the settings to change. Any suggestions guys?

Thanks, and sorry again for posting a non-VB question. I figured no one would read it on one of the other forums.


Saving Only Selected Outlook Attachments
The following caode saves all attachments in an email but how do I save only the selected (highlighted) attachments from an email

Sub SaveAttachments()
    Dim myOlapp As Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myFolder As Outlook.MAPIFolder
    Dim myItem As Outlook.MailItem
    Dim myAttachment As Outlook.Attachment
    Dim I As Long
    Set myOlapp = CreateObject("Outlook.Application")
    Set myNameSpace = myOlapp.GetNamespace("MAPI")
    Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
    Set myFolder = myFolder.Folders("Job Stuff")
    For Each myItem In myFolder.Items
        If myItem.Attachments.Count <> 0 Then
            For Each myAttachment In myItem.Attachments
                I = I + 1
                myAttachment.SaveAsFile "C:MailTestAttachment" & I & ".csv"
        End If
End Sub



When you call out for help in the darkness, and you hear a voice in return, you're probably just talking to yourself again!

HELP ME! Sending Multiple Attachments Using Outlook
Although I feel the code isn't necessarily for beginners, I am pretty poor at VB (although learning)

Basically, I am trying to create a facility that will send a number of attachments to a number of people and I just don't know where to start!

I have put down some code for sending a single message with a single attachment and that seems to work fine. The problem is I want to design a front page where the user can enter the attachment(s) then state who it goes to (again multiple). This mail would then be sent at a certain time on a certain day (possibly through Windows Task Scheduler??)

I know it's a bit of a major task but if anyone could help then I would be forever in their debt!



Outlook Only Save Selected Attachments
My problem is that I want to save only the attachments (from a open mail) that I drag and drop from Outlook to my application.
As it is now I get all attachments even if I did not select them.

I really need some help.


Automatically Printing PDF Attachments In Outlook
I receive a lot of email messages that have PDF attachments included. I need a way to print these attachments out automatically when they are received for audit purposes. It is time consuming if I have to right click on each attachment to print it out. Is there a way to do this in Outlook 2007 VBA?

Automatically Download Attachments From Outlook
Hi - is there a way to download files in outlook which have come from certain emailaddresses, in the same sort of way that rules work?

Edited by - Jrogers on 8/9/2006 9:05:50 AM

Script To Save Attachments From Outlook
I have an outlook file (.pst) of about 600MB. It has about 3k messages, a lot of them having attachments. How to make a program so I can save all attachments. The acrhive is becoming too big and I have to write all these attachments on CD. Thank you!

How Can I Read An Outlook .msg File That Is Saved On My Hard Disk

How can i read an outlook msg file that is saved on my system (local drive/network path)

so i could pass the address of file and then read the file ie (subject, email body etc)

i have installed outlook on my system.


Read Email Attachments From Exchange Server - Pls Help
Have really looked everywhere for this but cant seem to get a straight answer.

Am writing a service with VB .net that needs to read emails and download attachments from an Exchange Server. Service is running on a machine without outlook installed.

From what I understand, I cant use MAPI as its not supported and I cant use an outlook object within the service (message capture etc).

I've seen examples of WebDAV and CDOSYS. Is this the way to go? Am I ok to use an outlook object and MAPI within the service?

Please, really stuck on this. Any help really appreciated.

Drag And Drop Attachments From Outlook In A VB Application
Is there a way to get the path of the attachments from a outlook email out of the drag drop event?


Search Outlook For Attachments From Access Database
I hope that this makes sense! I'm still learning!
I want to search through an outlook folder for e-mails from a particular sender from within an access database. The e-mail csv attachments then need to be moved into an import folder. I then hope to import the attachments into various tables within the database.

I've done a little bit of code on the search and move function which doesn't work and I would very much appreciate if some of you experts out there could point me in the right dirrection.

Private Sub btnImportFiles_Click()

Dim outOutlook As Outlook.Application
Dim outNamespace As Outlook.NameSpace
Dim outItem As Outlook.MailItem
Dim strBody As String
Dim intAnswer As Integer
Dim outFolder As MAPIFolder
Dim destFolder As MAPIFolder
Dim intCount As Integer
Dim intMove As Integer
Dim intCount2 As Integer
Dim intAttachments As Integer

Set outOutlook = New Outlook.Application
Set outNamespace = Outlook.GetNamespace("MAPI")
Set outFolder = outNamespace.Folders("Public Folders").Folders("All Public Folders").Folders("Finance").Folders("RI Ledgers").Folders("RIL.Direct")

intCount = outFolder.Items.Count
Do Until intMove = intCount
intMove = intMove + 1

Set outItem = outFolder.Items(intMove)
If outItem.SenderName = "Automated Systems" Then
intCount2 = outItem.Attachments.Count
Do Until intAttachments = intCount2
intAttachments = intAttachments + 1


outItem.Attachments.Item(1).SaveAsFile ("G:
einledgMidnightJardinesLPCCashAttachmentsToBeLoaded" & outItem.Attachments.Item(1).DisplayName)
outItem.Move outNamespace.Folders("Public Folders").Folders("All Public Folders").Folders("Finance").Folders("RI Ledgers").Folders("RIL.Direct").Folders("Loaded Statements")

End If


MsgBox "Done"

End Sub

Access, Outlook Express, MAPI And Attachments
Hi all!

Currently I am working on a Access database -- after the user ends importing data to the tables and run macro which make corresponding output (text file), and he has to send this file to the recipients.

The problem is -- I still cannot find a way how to to attach this generated text file to the message. The message by itself is generated and send - no problem.

The code:
Type MAPIRecip
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As String
End Type

Type MAPIFileTag
Reserved As Long
TagLength As Long
Tag() As Byte
EncodingLength As Long
Encoding() As Byte
End Type

Type MAPIFile
Reserved As Long
Flags As Long
Position As Long
PathName As String
FileName As String
FileType As Long
End Type

Type MAPIMessage
Reserved As Long
Subject As String
NoteText As String
MessageType As String
DateReceived As String
ConversationID As String
Originator As Long
Flags As Long
RecipCount As Long
Recipients As Long
Files As Long
FileCount As Long
End Type

Declare Function MAPISendMail _
Lib "c:program filesoutlook expressmsoe.dll" ( _
ByVal Session As Long, _
ByVal UIParam As Long, _
Message As MAPIMessage, _
ByVal Flags As Long, _
ByVal Reserved As Long) As Long

Sub SendMailWithOE(ByVal strSubject As String, ByVal strMessage As String, _
ByRef aRecips As Variant)
Dim recips() As MAPIRecip
Dim oAttachments(1) As MAPIFile
Dim Message As MAPIMessage
Dim z As Long

ReDim recips(LBound(aRecips) To UBound(aRecips))
For z = LBound(aRecips) To UBound(aRecips)
With recips(z)
.RecipClass = 1

If InStr(aRecips(z), "@") <> 0 Then
.Address = StrConv(aRecips(z), vbFromUnicode)
.Name = StrConv(aRecips(z), vbFromUnicode)
End If
End With
Next z

With oAttachments(1)
.PathName = "<PATH TO FILE>"
End With

With Message
.NoteText = strMessage
.Subject = strSubject
.RecipCount = UBound(recips) - LBound(aRecips) + 1
.Recipients = VarPtr(recips(LBound(recips)))
.FileCount = 1
End With

MAPISendMail 0, 0, Message, 0, 0

End Sub

Sub TestSendMailwithOE()

Dim strSubject, strBody
Dim aRecips(0 To 0) As String

aRecips(0) = "SomeOne@Somewhere"
strSubject = "TEST"
strBody = "TEST"
SendMailWithOE strSubject, strBody, aRecips

End Sub

As I suppose, the solution is simple - if one knows it, of course.

Any help would be appreciated

Not A Vb Question - Problem With Outlook 2000 And Attachments
one of our reps called me today and is having a problem opening his attachments. its making all the attachments into a link and he has to "save target as" to view the attachment. i can not find an option anywhere in outlook to change this. does anyone know how to go back to the default way outlook has the files?

Copyright © 2005-08, All rights reserved