office-interop

Does *every* Excel interop object need to be released using Marshal.ReleaseComObject?

I've seen several examples where Marshal.ReleaseComObject() is used with Excel Interop objects (i.e., objects from namespace Microsoft.Office.Interop.Excel), but I've seen it used to various degrees. I'm wondering if I can get away with something like this: var application = new ApplicationClass(); try { // do work with application...

Adding reference to Office library failing: type or namespace name Word not found

I'm trying to use the sample code here: I went to "Add Reference" dialog and added "Microsoft Word 12 library", but it doesn't appear in the Solution Explorer. I also added: using Microsoft.Office; I get the following error message when trying to declare a "Word" object. Error 1: The type or namespace name 'Word' could not be f...

Select Range by string

How I can change this feature so I select the range of characters in a word document between the characters "E" and "F", if I have; xasdasdEcdscasdcFvfvsdfv is underlined to me the range -> cdscasdc private void Rango() { Word.Range rng; Word.Document document = this.Application.ActiveDocument; object startLocation = "E"; object endLo...

Excel COM Interop - tlbimp vs primary WrapperTool

I'm trying to add the ActiveX Microsoft Excel 11.0 Object library to my .NET project. It works fine on my computer, but when I check in my code, it doesn't work on my coworker's. Fixed it on his and it broke mine. When added, the namespaces are different between our machines. It turns out the difference is that when I add the reference ...

Multiple headers with Interop.Word

Hi, I am adding header and footer with Interop.Word and creating a Word document. I am adding an image and and text in the header and footer. When I run the application for the first time, the header and footer gets inserted. But when I run the application the next time, the header and footer keeps getting added and the whole document ge...

Reading records from Excel PivotCache

I have an Excel workbook which contains a PivotCache I would like to use as a data source. var file = @"Foo.xls"; var excel = new Excel.Application(); var workbook = excel.Workbooks.Open(file); Excel.PivotCache cache = null; foreach (Excel.PivotCache pivotCache in workbook.PivotCaches()) { if (...) { cache = pivotCache;...

How to check if .NET programmability support is installed for Word 2007?

Does anyone know how to check if the Office Interops were installed? I know it is an advanced option when installing Office 2007. Is there a way to install the support after Office is already installed? ...

new document format for word interop add-in

I'm having some trouble with a word add-in. I'm attempting to create a new document format, and have it sort-of working. The format is just an encoding on top of an existing docx. In other words, I can strip off the encoding and be left with a valid word document. Saving: Right now, when the user wants to save a document in the new f...

Is there a simple way to pull in the outlook message folder information in vs2010/.net 4.0 office 2007?

I'm building an outlook add-in to get around whatever the reasoning is you can't create a rule to sort mail based on a Distribution Group (error message about it being a personal distribution group). I've gotten really far and I think all the core functionality works, but I can't seem to figure out how to allow the user to drag/drop the...

Fastest way to write cells to Excel with Office Interop?

I am writing a function to export data to Excel using the Office Interop in VB .NET. I am currently writing the cells directly using the Excel worksheet's Cells() method: worksheet.Cells(rowIndex, colIndex) = data(rowIndex)(colIndex) This is taking a long time for large amounts of data. Is there a faster way to write a lot of data t...

How can I access an Outlook message using a unique and stable identifier?

Hi, I'm building an application that analyzes Outlook email messages, stores the analyzed information, and later allows the user to open messages meeting certain criteria. I expected that I would extract the Message-ID from each email, store this in my database, and then ask Outlook to open up a message by providing it with the Message...

Connecting to an existing Outlook process

Hi, I'm building an application that opens existing mail messages in Outlook. The user may or may not already be running Outlook. All works well if Outlook is not running, but if it's already running I get a COM error (80080005). The internet seems to indicate that this can happen if the existing Outlook process is running with a higher...

How to retrieve links between PowerPoint slides within a presentation

I`m looking for a way to read a links between slides in single PowerPoint presentation. I need to open a PowerPoint file and retrieve all links slides have to each other. Right now I`m using Aspose but it appears they do not have anything to read links between slides. I've read some more about the PowerPoint 2007/2010 file format and ...

Automate Word plug-ins

We are planning to automate the different plug-ins available in a Word document. Using C#, we need to interact with textbox, buttons and other controls available in a given plug-in. Is there any way to automate this? The solution should work with both Word 2003 & 2007. ...

Formatting a plain text e-mail in C#

I am trying to print a table inside an e-mail using plain text. I have the following code: string body = string.Format("{0,-30}{1,-30}{2,-50}{3,-40}", "Col1", "Col2", "Col2", “Col4”); body += string.Format("{0,-30}{1,-30}{2,-50}{3,-40}", value1, value2, value3, value4);...

How to make correct date format when writing data to Excel

Iam exporting a DataTable to an Excel-file using office interop. The problem is, that Excel does not recognize dates as such, but instead it displays numbers. In another case I pass a string which it then recognizes as a date. In both cases the data is messed up. I tried NumberFormat @ which is supposed to store the cell in text format,...

Using Microsoft Office Interop to create and parse Excel spreadsheets from ASP.NET.

I have a new ASP.NET MVC project that has two requirements that require using the Office Interop DLLs to generate Excel spreadsheet files in Excel 2003 format by combining several template files into a multi-sheet workbook and to parse these files once filled in. The files we parse may come back in Excel 2003, 2007 or 2010 format (I beli...

disabling overwrite existing file prompt in Microsoft office interop FileSaveAs method

Hi, I am using Ms Office Interop assemblies to create a MS Project file. To save the file created, I am using FileSaveAs method and it prompts a message saying that if you want to replace the existing file. I want to suppress the message, and I didn't find any parameter in FileSaveAs method for this purpose. Any Idea on this? I'am using ...

Document.SaveAs method withoud password ?

I want to save as a document without a password. The method SaveAs 4. and 6. parameters Password --> A password string for opening the document. (See Remarks below.) WritePassword --> A password string for saving changes to the document. (See Remarks below.) If I use the object missing = string.Empty and object missing = System.Reflecti...

Word/Office Automation - How to retrieve selected value from a Drop-down form field

Hi, I am trying to retrieve the value of all fields in a word document via office automation using c#. The code is shown below however if the field is a drop-down then the value of the range text is always empty even though I know it is populated. If it is a simple text field then I can see the range text. How do I get the selected d...