The type or namespace name 'Excel' could not be found
-
This is the correct way to do it, as described here[^].
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Hi everyone, I'm working in VS2010 and trying to create an app that interacts with Excel. I've added The MS Excel 14.0 Object Library reference (COM Tab) and at the top of my code I have the following:
using Microsoft.Office.Interop;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Word;I've tried to do:
var x1 = new Excel.Application();
and I get the error. My project is .Net framework 4. I've tried to find an answer on Google and did what was suggested on a few other forums but still this is not working for me anyone any ideas why?
-
That doesn't work in .NET 2.0+, since you can't prefix a class name with a "part" of the namespace like that.
Bastard Programmer from Hell :suss:
OP is using .NET 4.0.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
i think you should use "Add reference", right click on form->Add reference, there you will get all the namespace which are available. :)
-
OP is using .NET 4.0.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Shouldn't work in 4.0 either, but I'm too lazy to give it a try right now :)
Bastard Programmer from Hell :suss:
Eddy Vluggen wrote:
Shouldn't work in 4.0 either
I've used it in 3.0 and it worked fine. Did you read the linked article I referred to?
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Eddy Vluggen wrote:
Shouldn't work in 4.0 either
I've used it in 3.0 and it worked fine. Did you read the linked article I referred to?
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
That tells us that you have probably used VB to implement the example, as C# doesn't allow a prefix of the classname with a partial namespace;
Namespace Mine.Test
Public Class SomeClass
Public Property P As Guid
End Class
End Namespace--
Imports ScratchVb.Mine
Module Module1
Sub Main()
' VB.NET allows you to use "a part" of the namespace as a prefix
Dim X As Object = New Test.SomeClass()
End Sub
End Moduleusing System;
namespace Mine.Test
{
class SomeClass
{
public Guid P { get; set; }
}
}--
using Mine;
namespace Scratch
{
class Program
{
static void Main(string[] args)
{
// Prefixing a part of the name isn't allowed
Object X = new Test.SomeClass();
// Full namespace is allowed, of course;
Object X = new Mine.Test.SomeClass();
}
}
}Yes, read the article some time ago. Did you try it? :)
Bastard Programmer from Hell :suss:
-
That tells us that you have probably used VB to implement the example, as C# doesn't allow a prefix of the classname with a partial namespace;
Namespace Mine.Test
Public Class SomeClass
Public Property P As Guid
End Class
End Namespace--
Imports ScratchVb.Mine
Module Module1
Sub Main()
' VB.NET allows you to use "a part" of the namespace as a prefix
Dim X As Object = New Test.SomeClass()
End Sub
End Moduleusing System;
namespace Mine.Test
{
class SomeClass
{
public Guid P { get; set; }
}
}--
using Mine;
namespace Scratch
{
class Program
{
static void Main(string[] args)
{
// Prefixing a part of the name isn't allowed
Object X = new Test.SomeClass();
// Full namespace is allowed, of course;
Object X = new Mine.Test.SomeClass();
}
}
}Yes, read the article some time ago. Did you try it? :)
Bastard Programmer from Hell :suss:
Eddy Vluggen wrote:
That tells us that you have probably used VB to implement the example, as C# doesn't allow a prefix of the classname with a partial namespace;
Wrong on both counts.
Eddy Vluggen wrote:
Yes, read the article some time ago. Did you try it?
Yes I tried it, using C# as i)I never use or have used VB/VB.NET and ii)the title of the article is How to automate Microsoft Excel from Microsoft Visual C#.NET!
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
I've added the MS Excel 14.0 Object Library reference (COM Tab), Richard the link that you have recommended is one that I have already followed but I was still getting the error.
pmcm wrote:
Richard the link that you have recommended is one that I have already followed but I was still getting the error.
Can you show your code and the exact text of the error message?
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Eddy Vluggen wrote:
That tells us that you have probably used VB to implement the example, as C# doesn't allow a prefix of the classname with a partial namespace;
Wrong on both counts.
Eddy Vluggen wrote:
Yes, read the article some time ago. Did you try it?
Yes I tried it, using C# as i)I never use or have used VB/VB.NET and ii)the title of the article is How to automate Microsoft Excel from Microsoft Visual C#.NET!
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Richard MacCutchan wrote:
Yes I tried it, using C#
Never mind :)
Bastard Programmer from Hell :suss:
Eddy Vluggen wrote:
Never mind
I don't mind, it's you that kept banging on about it, like a :mad:
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
pmcm wrote:
Richard the link that you have recommended is one that I have already followed but I was still getting the error.
Can you show your code and the exact text of the error message?
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
I fixed this issue by doing:
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;
using Word = Microsoft.Office.Interop.Word;That's what I suggested yesterday.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman