RE: Decleration Excel.Application or what



Hi Bruno,

I believe that the behavior that you are seeing is the result of a .NET
security error when you call into the NanoSort class.

When you create and build your VSTO project a .NET security policy is
automatically created for you. This policy is setup specifically for the
assembly generated from your VSTO project.

Based on the code that you provided I am going to assume that you've added a
reference to the NanoSort class within your VSTO project and that the
CopyLocal property of the reference is set to True, which is the default.

If this is the case you should be able to modify the security policy that
was created for the VSTO assembly so that it trusts the folder where the
assemblies reside rather than just the VSTO assembly and this should correct
the problem that you're having.

Another option would be to Strong Name the assembly containing the NanoSort
class and then create a .NET security policy using Strong Name evidence for
this assembly.

Hope this helps!

If you have any questions please let me know via the posting.

Regards,

Ken Laws
Microsoft Support


This posting is provided "AS IS" with no warranties, and confers no rights.

For more information regarding Visual Studio Tools for Office 2005:

Best of Blogs: Visual Studio 2005 Tools for Office
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_2003_ta/html/odc_landvsto2005_ta.asp

Visual Studio Tools for Office Forum
http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16

Visual Studio Tools for the Microsoft Office System
http://msdn.microsoft.com/office/understanding/vsto/default.aspx


"Bruno Uato" wrote:

> Hello,
> I have in the office code behind class following code
>
> Private Sub MenuItem_Click(ByVal Ctrl As
> Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As
> Boolean) Handles MenuItem.Click
> Forms.MessageBox.Show("Hello")
> Dim a As New NanoTools.NanoExcel.NanoSort
> Forms.MessageBox.Show(a.SelectionAddress)
>
> End Sub
>
> In an second Project I have
>
> Namespace NanoTools.NanoExcel
>
> Public Class NanoSort
>
> Public appExcel As Excel.Application = CType(GetObject(,
> "Excel.Application"), Microsoft.Office.Interop.Excel.Application)
>
>
> Public ReadOnly Property SelectionAddress() As String
> Get
> Return
> CType(appExcel.ActiveWindow.RangeSelection.Address, String)
> End Get
> End Property
>
> End Class
> End Namespace
>
> If I push the button, i got the "Hello" but not the
> Address....nothing, no failure or anything else. If I replace the line
> Return xxx with Return "something" it works. What is wrong with the
> code or declaration of appExcel?
>
> Thanks in advance, Bruno
>
.