[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Download attachment from outlook

Posted on 2014-12-04
8
Medium Priority
?
127 Views
Last Modified: 2014-12-06
Hi,

I was hoping some of the more experienced VBA users will be able to help me with some coding please? This has been driving me insane.  I have a demo program which works perfectly fine, On the treeview I am able to select a sub folder within my inbox, I am able to click browse and when I click on the get attachment button it downloads the attachment fine.  I am trying to do the same on my excel program, the only difference is that I require no treeview, no textbox and no browse button.  The textbox (destination) will be coded in, also the subfolder in my inbox will be coded in (so I have a sub folder called Test inside my inbox folder).  I have tried to edit the coding but I get

An unexpected error has occurred.
Please note and report the following information
Macro GetAttachments
Error Number:91
Error Description Object variable or with block variable not set

I have attached the demo program and my my version which is based from the demo program.  I would really appreciate any help.
Download-Attachment.zip
0
Comment
Question by:Legolas786
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40481207
This is from the web

Public Function GetFolder(strFolderPath As String)As MAPIFolder
  ' strFolderPath needs to be something like 
  '   "Public Folders\All Public Folders\Company\Sales" or
  '   "Personal Folders\Inbox\My Folder"

  Dim objApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  Dim colFolders As Outlook.Folders
  Dim objFolder As Outlook.MAPIFolder
  Dim arrFolders() As String
  Dim I As Long
  On Error Resume Next

  strFolderPath = Replace(strFolderPath, "/", "\")
  arrFolders() = Split(strFolderPath, "\")
  Set objApp = Application
  Set objNS = objApp.GetNamespace("MAPI")
  Set objFolder = objNS.Folders.Item(arrFolders(0))
  If Not objFolder Is Nothing Then
    For I = 1 To UBound(arrFolders)
      Set colFolders = objFolder.Folders
      Set objFolder = Nothing
      Set objFolder = colFolders.Item(arrFolders(I))
      If objFolder Is Nothing Then
        Exit For
      End If
    Next
  End If

  Set GetFolder = objFolder
  Set colFolders = Nothing
  Set objNS = Nothing
  Set objApp = Nothing
End Function

Open in new window

0
 
LVL 26

Expert Comment

by:Nick67
ID: 40481364
Ok,

Clearly your sample isn't complete.
I have got it past it's first hurdle, opening Outlook correctly
Here it is back.

It doesn't compile because you haven't yet put in where it's getting folders from etc.
On error Goto is an EVIL thing.
Especially when your DEVELOPING -- as it keeps you from finding your errors.
At best, turn that on in the very end after you are certain no bugs remain.
Download-Outlook-Attachments-My-Version.
0
 

Author Comment

by:Legolas786
ID: 40481381
Hi what format is the file as i am unable to open it?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 26

Expert Comment

by:Nick67
ID: 40481385
EE bug with the extra long name I expect.
Right-click it and save it as test1.xls
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40481411
Your next hurdle is that the userform did this
Set oFldrList = oNameSpace.GetDefaultFolder(olFolderInbox)
You need to do it, now too, in GetAttachments

The userform used to pass in Name
GetAttachments(Name As String)
Name was the subfolder of inbox to parse
You need to make this equal to a cell value after parsing it to see if it exists

You've gotten rid of
frmdownloadattchmts.TextBox1.Value
You need to substitute in a cell value, too
0
 

Author Comment

by:Legolas786
ID: 40481412
hi, i tried that but it says that file is corrupted?
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40481417
Give me a bit
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 1000 total points
ID: 40481488
Ok,
Subfolder of Inbox in A1
Destination in A2
click the button
SaveAttms.xls
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question