2 Replies - 409 Views - Last Post: 28 June 2012 - 03:10 AM Rate Topic: -----

#1 MVSb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-June 12

Statement is not Valid in a Namespace

Posted 27 June 2012 - 11:20 PM

When i have used a code, i got the following problems
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

Is This A Good Question/Topic? 0
  • +

Replies To: Statement is not Valid in a Namespace

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1956
  • View blog
  • Posts: 8,700
  • Joined: 29-May 08

Re: Statement is not Valid in a Namespace

Posted 28 June 2012 - 12:49 AM

Statement is not Valid in a Namespace means the code isn't inside of a Module, Class or Structure.
Was This Post Helpful? 1
  • +
  • -

#3 MVSb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-June 12

Re: Statement is not Valid in a Namespace

Posted 28 June 2012 - 03:10 AM

FInally i got the problem solved myselfs..
i have not included the references
we must add reference Microsoft office outlook library. You can add reference from
1. View
2. Add Reference
3. under C# tab
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1