LinqPad 7 - C# - Microsoft.VisualBasic.Interaction.GetObject - linqpad

Solved by Comment from Joe Albahari
In LinQPad 7 I try to connect to an open Excel Application.
In C# .net this is easy done by eg:
public Microsoft.Office.Interop.Excel.Application ExcelApplication; ExcelApplication = (Application)Microsoft.VisualBasic.Interaction.GetObject(Class: "Excel.Application");
With references to Microsoft.Office.Interop.Excel and Microsoft.VisualBasic
In LinQPad 7 I tried the same but ExcelApplication is null (Yes Excel is open!)
References are set and Namespace imported.
It shows no error, just does not connect.
What am I doing wrong?
(The example from LinqPad for Excel creates a new excel application.
thanks for any help

Related

MsoAutomationSecurity is ambiguous in the namespace of Microsoft.Office.Core

I am trying to use Microsoft.Office.Core.MsoAutomationSecurity in vb.net to set the security mode of an application when opening an excel file. But when I declare this variable on my code in vb.net:
Dim secAutomation As New Microsoft.Office.Core.MsoAutomationSecurity
it has a blue lining below Microsoft.Office.Core.MsoAutomationSecurity and on the Error window, this is listed:
'MsoAutomationSecurity' is ambiguous in the namespace 'Microsoft.Office.Core'
Type 'Microsoft.Office.Core.MsoAutomationSecurity' is not defined.
I hope anyone could help me fix this.
EDITED:
Imports OfficeCore = Microsoft.Office.Core
Imports excelApp = Microsoft.Office.Interop.Excel
Sub ExcelSecurity()
Dim secAutomation As OfficeCore.MsoAutomationSecurity
secAutomation = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow
End Sub
thank you!
The main problem with this question is that on one (1) solution there are 4 projects. The reference on the other projects has a duplicate Reference when adding the said Reference which is the Microsoft Office 14.0 Object Library. When I see the References on the other projects, the Microsoft Office 14.0 Object Library has a duplicate with different versions, to fix this problem I just removed the outdated version of the Reference.
This error throws due to not add reference for MS Office which installed on your machine. Under project solution > References > Add references > COM > Microsoft office 16.06 Object library marked as checked and saved.
After showing your code minor modification needed as below:
Imports OfficeCore = Microsoft.Office.Core
Imports excelApp = Microsoft.Office.Interop.Excel
Sub ExcelSecurity()
Dim secAutomation As OfficeCore.MsoAutomationSecurity
secAutomation = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow
End Sub
I hope it will resolve your issue without any other changes. Let me know if any further issues.

VBA office 2016 windows7/10 difference: Set IXMLDOMNodeList = DOMDocument60.childNodes

I've got an issue with a piece of VBA code that runs fine on a windows 7 machine, but doesn't work on windows 10. My VBA skills aren't good enough to figure this one out.
This part of the code in run in a Excel class and is used to load a xml file and return the xml as a class.
Public Function GetDomNodeList(ByRef log As Logger) As MSXML2.IXMLDOMNodeList
Dim domdocument As New MSXML2.DOMDocument60
'Open file for handling
domdocument.async = False
domdocument.Load (strThisFilePath)
'Call the helper sub to do the actual work:
Set GetDomNodeList = domdocument.childNodes
End Function
When debugging it tells me there is a type mismatch. I've tried to debug the issue, but I'm running short on knowledge here. My main question is why this works on windows 7 and why not on windows 10 running the same office version (2016) VBA7.1
After a lot of trials I found a solution. Export the class, remove it and import the class again and all magically works again. I'm baffled by this.

Visual Basic in VS 2013 and Excel 2010: cannot find xlQualityStandard (is not declared)

I am trying to code some Excel automation stuff using VB in VS2013. Basically, I can perform a lot of excel operation from my code (even applying the data analysis tool, and creating histograms).
However, in my case, Visual Studio is complaining 'xlQualityStandard' is not declared.
Here is a sample of my code
Imports Microsoft.Office
Imports Excel = Microsoft.Office.Interop.Excel
' do something
xlTempSheet.ExportAsFixedFormat(Type:=Excel.XlFixedFormatType.xlTypePDF, Filename:="c:\plots test\test.pdf",
IgnorePrintAreas:=True, OpenAfterPublish:=True, Quality:=xlQualityStandard)
If I remove
Quality:=xlQualityStandard
The code will just work.
In my case,
Excel.XlFixedFormatQuality.xlQualityStandard
will work. Thanks to user2930100
The values can be found here
https://msdn.microsoft.com/en-us/library/bb241292(v=office.12).aspx
xlQualityMinimum 1 Minimum quality
xlQualityStandard 0 Standard quality
Interestingly Google now seems to provide API help

Error importing and exporting excel data to vb.net, "Microsoft.Office.Interop.Excel.Application is not defined"

I am trying to run a file I downloaded to import and export data from excel.
I downloaded from from the following site:
http://www.sattsoft.com/sourcecodes/details/1/9/import-export-data-to-excel-using-vb-net.html
When I run the file the error comes on the following lines
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
These are the errors that come on those respective lines
Type "Microsoft.Office.Interop.Excel.Application is not defined"
Type "Microsoft.Office.Interop.Excel.Workbook is not defined"
Type "Microsoft.Office.Interop.Excel.Worksheet is not defined"
What I want to do is to run the file without the errors so that I can import and export data from excel to vb.net datagridview.
I am using Excel 2010 and visual studio 2010
How do I get around this error so I can run the file?
Add COM reference Microsoft.Office.Interop.Excel to your project, it's called Microsoft Excel XX.Y Object Library (XX.Y is version number depending of installed Excel).
I had to use this library in references from the "Extensions" section (not not under COM); had to select Microsoft.Office.Interop.Excel, version 15.0.0.0.
That fixed the error.
Selecting the COM reference did not resolve this message.

Cannot create new Excel.Application

I have this class in which I want to create a new Excel application to export some data to an Excel workbook, but I can't seem to create the application itself.
I already added the Microsoft.Office.Interop.Excel.dll reference to the Bin folder:
And tried to add the code like this:
Imports Microsoft.VisualBasic
Imports Excel = Microsoft.Office.Interop.Excel
Public Class ExcelExport
Public Sub Export()
Dim excel As New Excel.Application
End Sub
End Class
But when I do I can't find the Application:
Any ideas why it wont work?
VS 2008, VB.NET, .NET 3.5, Office 2007, Windows 7 Ultimate x64