Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Excel 2007 automation on top of a Windows Server 2008 x64 [modified]

Excel 2007 automation on top of a Windows Server 2008 x64 [modified]

Scheduled Pinned Locked Moved COM
csscomdesignsysadminwindows-admin
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chris Richner
    wrote on last edited by
    #1

    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 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 open operation ends in this exception: Service cannot be started. System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file 'c:\temp\test.xls'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook. Why was the automated excel able to launch and write files to disk but fails when it’s asked “just “ to open an existing file?

    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
    // launch excel and create/save a new work book
    Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
    excel.UserLibraryPath, excel.Interactive));
    //
    string filename = "c:\\temp\\test.xls";
    if(System.IO.File.Exists(filename)) System.IO.File.Delete(filename);
    //
    excel.Workbooks.Add(System.Reflection.Missing.Value);
    excel.Save(filename);
    excel.Quit();
    excel = null;
    // lauch new instance of excel and open saved file
    excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
    try
    {
    Microsoft.Office.Interop.Excel.Workbook book = excel.Workbooks.Open(filename,
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    true,
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    false,
    false,

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups