none
not declare"Application”. it maybe casued by protect level that can not access. RRS feed

  • Question

  • I create a outlook 2010 object by VS2010, for below code, the 3rd line, "objApp = Application" . the error shows

    未声明“Application”。它可能因其保护级别而不可访问。

    Sorry I am not sure how to translate to english.

    not declare"Application”. it maybe casued by protect level that can not access.

    Function GetCurrentItem() As Object
            Dim objApp As Outlook.Application

            objApp = Application
            On Error Resume Next
            Select Case TypeName(objApp.ActiveWindow)
                Case "Explorer"
                    GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
                Case "Inspector"
                    GetCurrentItem = objApp.ActiveInspector.CurrentItem
            End Select

            objApp = Nothing
        End Function


    • Edited by beastwars Friday, November 2, 2012 1:37 PM
    Friday, November 2, 2012 1:34 PM

Answers

  • HI beastwars

    You mention that you've created this solution using VS 2012, but you haven't specified what kind of application it is. What template did you choose from Visual Studio's File/New dialog box? Windows Form? Console Application? Outlook Add-in? Something else?

    Probably, .NET is not able to identify exactly what is meant by "Application". Usually, "Application" will mean the Visual Studio solution in which the code is running, but that would not be equivalent to the data type Outlook.Application.

    Since this is the VSTO forum our first inclination would be to think that this is an Outlook Add-in. If that is the case, try:
      objApp = Globals.ThisAddin.Application


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by beastwars Friday, November 2, 2012 4:41 PM
    Friday, November 2, 2012 2:41 PM
    Moderator

All replies

  • HI beastwars

    You mention that you've created this solution using VS 2012, but you haven't specified what kind of application it is. What template did you choose from Visual Studio's File/New dialog box? Windows Form? Console Application? Outlook Add-in? Something else?

    Probably, .NET is not able to identify exactly what is meant by "Application". Usually, "Application" will mean the Visual Studio solution in which the code is running, but that would not be equivalent to the data type Outlook.Application.

    Since this is the VSTO forum our first inclination would be to think that this is an Outlook Add-in. If that is the case, try:
      objApp = Globals.ThisAddin.Application


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by beastwars Friday, November 2, 2012 4:41 PM
    Friday, November 2, 2012 2:41 PM
    Moderator
  • OP acknowledged this to be the answer in

    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/e71ca21d-3d08-4c09-9641-95ccaf571980

    where he also asked a new question. That was split into a new discussion as the question was completely different.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, November 2, 2012 3:43 PM
    Moderator