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. C#
  4. Excel Macro from C#

Excel Macro from C#

Scheduled Pinned Locked Moved C#
helpcsharpwpfquestion
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.
  • P Offline
    P Offline
    pssuresh
    wrote on last edited by
    #1

    Hi all, I am calling excel macro function which is available in excel template file. I get the reference of the work sheet, and iam trying to calling a macro from C#.The code is as below. System.Diagnostics.Process[] myProcesses; Excel.ApplicationClass appInstanceReference; myProcesses = System.Diagnostics.Process.GetProcessesByName("EXCEL"); if ( myProcesses.Length > 0 ) { Excel.Workbook xlwkbook = (Excel.Workbook) System.Runtime.InteropServices.Marshal.BindToMoniker(System.Windows.Forms.Application.StartupPath + @"\Templates\CommercialSizing.XLT"); if ( xlwkbook != null ) { appInstanceReference = (Excel.ApplicationClass) xlwkbook.Application; if ( appInstanceReference != null) { appInstanceReference.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, appInstanceReference,new object[] {"'" + System.Windows.Forms.Application.StartupPath + @"\Templates\CommercialSizing.XLT" + "'!YourMacro"} ); } } } The problem is, it is not just calling macro function, instead of that, it is opening new excel template and it is calling macro function, but the excel sheet is already opened, i just need to execute my macro.what is the change i need to do in my code.Thanks for your help.

    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