Warning : 1 Namespace or type specified in the Imports 'Microsoft.Office.Interop' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. C:\Documents and Settings\E1002176\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb 1 9 WindowsApplication1
Error : Statement is not valid in namespace.
My code is
Imports Microsoft.Office.Interop
Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim I As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
Dim Counter As Long
strFolderpath = "D:\attachments"
If (Dir$(strFolderpath, vbDirectory) = "") Then
MsgBox("'" & strFolderpath & "' not exist")
MkDir(strFolderpath)
MsgBox("'" & strFolderpath & "' we create it")
Else
MsgBox("'" & strFolderpath & "' exist")
End If
' Get the path to your My Documents folder
'strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
strFolderpath = strFolderpath & "\"
On Error Resume Next
' Instantiate an Outlook Application object.
objOL = CreateObject("Outlook.Application")
' Get the collection of selected objects.
objSelection = objOL.ActiveExplorer.Selection
' The attachment folder needs to exist
' You can change this to another folder name of your choice
' Set the Attachment folder.
strFolderpath = strFolderpath
' Check each selected item for attachments.
Counter = 1
For Each objMsg In objSelection
objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
' Use a count down loop for removing items
' from a collection. Otherwise, the loop counter gets
' confused and only every other item is removed.
For I = lngCount To 1 Step -1
' Get the file name.
strFile = objAttachments.Item(I).FileName
' Combine with the path to the Temp folder.
strFile = strFolderpath & Counter & "_" & strFile
' Save the attachment as a file.
objAttachments.Item(I).SaveAsFile(strFile)
Counter = Counter + 1
Next I
End If
Next
ExitSub:
objAttachments = Nothing
objMsg = Nothing
objSelection = Nothing
objOL = Nothing
MsgBox("All Selected Attachments Have Been Downloaded ...")
End Sub
Please help

New Topic/Question
Reply



MultiQuote




|