office-automation

Running an Excel Macro via C#: Run a macro from one workbook on another?

坚强是说给别人听的谎言 提交于 2019-11-28 11:14:53
I am looking to run a macro, let's call it Macro01 from WorkSheet01 on WorkSheet02. Using Microsoft.Office.Interop.Excel Namespace I have opened a WorkSheet01. public void Main_CodedStep() { // Object for missing (or optional) arguments. object oMissing = System.Reflection.Missing.Value; // Create an instance of Microsoft Excel Excel.ApplicationClass oExcel = new Excel.ApplicationClass(); // Make it visible oExcel.Visible = true; // Open Worksheet01.xlsm Excel.Workbooks oBooks = oExcel.Workbooks; Excel._Workbook oBook = null; oBook = oBooks.Open("C:\\Users\\Admin\\Documents\\Worksheet01.xlsm",

Printing with advanced options (tray selection, duplex, staple)

為{幸葍}努か 提交于 2019-11-28 10:34:18
We have a project of managing printing documents. At first I wonder why printing options couldn't be set up in single place. For example printer tray selection for first page and for other pages can be done using MS Word automation : var doc = _applicationObject.Documents.OpenNoRepairDialog(FileName: ref sourceFile, ReadOnly: ref readOnly, AddToRecentFiles: ref addToRecentFiles, Visible: ref visible); doc.PageSetup.FirstPageTray = (WdPaperTray) firstPageTrayCode; doc.PageSetup.OtherPagesTray = (WdPaperTray) otherPagesTrayCode; _applicationObject.ActivePrinter = printerPath; doc.Activate();

Editing an Excel document with Macros in ASP.net

人盡茶涼 提交于 2019-11-28 01:43:18
Is it possible in any way to edit an excel sheet through an ASP.net page that contains macro. I have tried to open the Excel sheet and it seems to just hang rather than load the excel. Testing on a page without macros works perfectly fine? xxbbcc Disclaimer : I don't know the Excel license agreement and I don't know if utilizing Excel in a server process violates it or not. This is purely a technical description of how to get it working. The reader is advised to check the license agreement to see if it's allowed to do so or not. Different Office versions may have different license agreements.

how to close a running instance of Word document? (C#)

此生再无相见时 提交于 2019-11-27 22:29:08
I could see a lot of very similar threads all around, but nothing seem to give me a solution which ought to be very basic. From my winforms application, I need to close a running instance of a word document (opened from the application itself). When I open the word document from the application, I keep a track of it in a list. Now how can I close the same doc? Here is what I tried: private bool CloseWord(string osPath) //here I pass the fully qualified path of the file { try { Word.Application app = (Word.Application)Marshal.GetActiveObject("Word.Application"); if (app == null) return true;

Killing EXCEL.exe Process from C# in a Windows Service

我怕爱的太早我们不能终老 提交于 2019-11-27 15:16:49
问题 I have a windows service that opens up an Excel spreadsheet via the Microsoft.Office.Interop.Excel.Application object. Application xlApp = new Application(); Workbook workbook = xlApp.Workbooks.Open(fileName, 2, false); ... ... workbook.Close(); xlApp.Quit(); I would like to kill the EXCEL.exe process that is left running after it is done working with the workbook. I've tried the following with no success... // This returns a processId of 0 IntPtr processId; GetWindowThreadProcessId(new

asp.net web service using office 2010 COM

亡梦爱人 提交于 2019-11-27 09:35:54
I am writing a web service and would like to change the .docx or .doc to .xps. I'm using office com to help me to save as .xps format as following: [WebMethod] public string GetDocPreviewUrl(string m_userName, string m_orgFileName) { string m_returnUrl = ""; string m_orgFilePath = _currentDirectory + "\\" + m_userName + "\\" + m_orgFileName; if (File.Exists(m_orgFilePath)) { string m_xpsFilePath = _currentDirectory + "\\" + m_userName + "\\" + Path.GetFileNameWithoutExtension(m_orgFileName) + ".xps"; OfficeToXpsConversionResult m_converstionResult = OfficeToXps.ConvertToXps(m_orgFilePath, ref

IE 9 not accepting SendKeys

倖福魔咒の 提交于 2019-11-27 07:17:32
问题 I posted on IE 9 not accepting SendKeys to download a file, but this problem is separate enough from the answer I received to justify another question. My problem is that I can't get IE 9 to accept any of the SendKeys . I have attempted Page Down , Tab , all of the F# keys, and none of them work. Here is the code I am using: Dim ie As Object 'This creates the IE object Sub initializeIE() 'call this subprocedure to start internet explorer up Set ie = CreateObject("internetexplorer.application"

Excel 2007 automation on top of a Windows Server 2008 x64

天大地大妈咪最大 提交于 2019-11-27 06:45:31
I’m well aware of the Microsoft support base article stating that it’s not supported to automate office products UI less. It seems that Windows Server 2008 x64 and Excel 2007 enforce the given statement. I’m running the following code in a NT Service (Local System account) OnStart method. All it does is Excel automation the way it’s working when you run the same code in a Console Application. The provided code has two parts. The first part launches Excel, creates a new work book and saves it to the given filename. The second part launches a new instance of Excel and opens the given file. The

Running an Excel Macro via C#: Run a macro from one workbook on another?

霸气de小男生 提交于 2019-11-27 06:00:20
问题 I am looking to run a macro, let's call it Macro01 from WorkSheet01 on WorkSheet02. Using Microsoft.Office.Interop.Excel Namespace I have opened a WorkSheet01. public void Main_CodedStep() { // Object for missing (or optional) arguments. object oMissing = System.Reflection.Missing.Value; // Create an instance of Microsoft Excel Excel.ApplicationClass oExcel = new Excel.ApplicationClass(); // Make it visible oExcel.Visible = true; // Open Worksheet01.xlsm Excel.Workbooks oBooks = oExcel

Editing an Excel document with Macros in ASP.net

浪子不回头ぞ 提交于 2019-11-26 23:33:43
问题 Is it possible in any way to edit an excel sheet through an ASP.net page that contains macro. I have tried to open the Excel sheet and it seems to just hang rather than load the excel. Testing on a page without macros works perfectly fine? 回答1: Disclaimer : I don't know the Excel license agreement and I don't know if utilizing Excel in a server process violates it or not. This is purely a technical description of how to get it working. The reader is advised to check the license agreement to