Help!

PC-Problemen?
De vrijwilligers van Oplossing.be zoeken gratis met u mee!

Hulp bij posten

Recente topics

Auteur Topic: Bijlage Outlook downloaden vanuit excel  (gelezen 2537 keer)

0 leden en 1 gast bekijken dit topic.

Offline cladon

  • Volledig lid
  • **
  • Berichten: 246
  • Geslacht: Man
Bijlage Outlook downloaden vanuit excel
« Gepost op: 17 januari 2007, 09:13:20 »
Hallo Met de onderstaande code kan je bijlages in outlook binnenhalen vanuit excel en deze bewaren in een bepaalde map op je hardeschijf.

'Attribute VB_Name = "GetEmailAttachments"
Option Explicit



'************************** Õ¿Õ- **************************
'*** Code by Martin Green ******** martin@fontstuff.com ***
'******* Office Tips Web Site - www.fontstuff.com *********
'**********************************************************

Sub GetAttachments()
'Dim appOl As New Outlook.Application

'Dim Inbox As Outlook.MAPIFolder
'Dim Atmt As Outlook.Attachment
'Set ns = appOl.GetNamespace("MAPI")
'Set appOl = Nothing

' This Outlook macro checks a the Outlook Inbox for messages
' with attached files (of any type) and saves them to disk.
' NOTE: make sure the specified save folder exists before
' running the macro.
    On Error GoTo GetAttachments_err
' Declare variables
Dim appOl As New Outlook.Application

Dim ns As Outlook.Namespace
Dim Inbox As Outlook.MAPIFolder
    Dim Item As Object
Dim Atmt As Outlook.Attachment
    Dim FileName As String
    Dim i As Integer
Set ns = appOl.GetNamespace("MAPI")
    Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set appOl = Nothing

    i = 0
' Check Inbox for messages and exit of none found
    If Inbox.Items.Count = 0 Then
        MsgBox "There are no messages in the Inbox.", vbInformation, _
               "Nothing Found"
        Exit Sub
    End If
' Check each message for attachments
    For Each Item In Inbox.Items
' Save any attachments found
        For Each Atmt In Item.Attachments
        ' This path must exist! Change folder name as necessary.
            FileName = "C:\Email Attachments\" & Atmt.FileName
            Atmt.SaveAsFile FileName
            i = i + 1
         Next Atmt
    Next Item
' Show summary message
    If i > 0 Then
        MsgBox "I found " & i & " attached files." _
        & vbCrLf & "I have saved them into the C:\Email Attachments folder." _
        & vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
    Else
        MsgBox "I didn't find any attached files in your mail.", vbInformation, "Finished!"
    End If
' Clear memory
GetAttachments_exit:
    Set Atmt = Nothing
    Set Item = Nothing
    Set ns = Nothing
    Exit Sub
' Handle errors
GetAttachments_err:
    MsgBox "An unexpected error has occurred." _
        & vbCrLf & "Please note and report the following information." _
        & vbCrLf & "Macro Name: GetAttachments" _
        & vbCrLf & "Error Number: " & Err.Number _
        & vbCrLf & "Error Description: " & Err.Description _
        , vbCritical, "Error!"
    Resume GetAttachments_exit
End Sub

Ik heb een verwijzing naar het objectmodel van outlook. Ik werk met versie 2003.

Bij het uitvoeren van de code krijg ik een automatiseringsfout met vermelding "kan opgegeven module" niet vinden.

Je kan de code ook vinden op www.fontstuff.com

De vraag is wat heb ik fout,  heeft hier iemand ervaring mee?
Windows 10 Home   NLD 64bit,
Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz 3401
P8B75-M LE
Intel(R) HD Graphics 4000 3072MB 1920 x 1080
VIA HD Audio
C:\ NTFS 237,25GB 135,35GB 15 293MB
AV: Kaspersky
FW: Windows 10

Offline RedHead

  • Excel-Expert
  • Ambassadeur
  • *****
  • Berichten: 2.284
  • Geslacht: Man
  • Met Excel lukt 't wel.... (toch???)
Re:Bijlage Outlook downloaden vanuit excel
« Reactie #1 Gepost op: 19 januari 2007, 11:47:46 »
Cladon, Ik heb hier geen ervaring mee, maar wil maar wat graag met je mee kijken als het gaat om zo'n mooi progammaatje.
Als je de (zeer) uitgebreide beschrijving leest van Martin Green, dan zie je dat dit een Outlookmacro is. Je moet 'm dus plaatsen in Outlook en van daaruit starten (tenminste... zo begrijp ik 'm!  ;)). Ik gok dat jij 'm in een Excelmodule hebt gezet... ???

Bovendien zie ik dat tie nog een mooie procedure heeft geschreven die puur naar .xls bijlagen kijkt en deze opslaat met een timestamp. Omdat je nu post in de Excel-sectie lijkt me deze code beter op z'n plaats? (maar verbeter me als ik er helemaal naast zit... ;))

Groet, Leo
______________________________

Groet, Leo

Offline cladon

  • Volledig lid
  • **
  • Berichten: 246
  • Geslacht: Man
Re:Bijlage Outlook downloaden vanuit excel
« Reactie #2 Gepost op: 19 januari 2007, 15:21:25 »
Ja het is een outlook-macro je je mits enkel kleine aanpassingen (terug te vinden op de pagina waar de broncode staat) en dan moet het ook werken vanuit excel.

Het probleem is nog niet van de baan maar onder tussen weet ik wel de oorzaak. Derze code werkte vroeger perfect - vorige week heb ik een windows-update gedaan waarbij er een nieuwe excelpatch was. Blijkbaar zit de oorzaak in een foutje in deze patch.
Windows 10 Home   NLD 64bit,
Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz 3401
P8B75-M LE
Intel(R) HD Graphics 4000 3072MB 1920 x 1080
VIA HD Audio
C:\ NTFS 237,25GB 135,35GB 15 293MB
AV: Kaspersky
FW: Windows 10

Offline RedHead

  • Excel-Expert
  • Ambassadeur
  • *****
  • Berichten: 2.284
  • Geslacht: Man
  • Met Excel lukt 't wel.... (toch???)
Re:Bijlage Outlook downloaden vanuit excel
« Reactie #3 Gepost op: 19 januari 2007, 21:07:47 »
Cladon, is het een idee om je vraag bij Martin Green (martin@fontstuff.com) zelf neer te leggen? Hij vraagt daar dan wel een kleine donatie voor... (zie z'n homepage)

Groet, Leo
______________________________

Groet, Leo

Offline cladon

  • Volledig lid
  • **
  • Berichten: 246
  • Geslacht: Man
Re:Bijlage Outlook downloaden vanuit excel
« Reactie #4 Gepost op: 19 januari 2007, 23:08:24 »
Ja - ik weet het - ik heb het nog niet dadelijk nodig en wacht af tot er van Microsoft een nieuwe update  (live update) van excel komt.
Windows 10 Home   NLD 64bit,
Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz 3401
P8B75-M LE
Intel(R) HD Graphics 4000 3072MB 1920 x 1080
VIA HD Audio
C:\ NTFS 237,25GB 135,35GB 15 293MB
AV: Kaspersky
FW: Windows 10

 


www.combell.com