0
votes

I have a program that Executes VBA excel file with parameters like

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;

object _ExcelPathLocation = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe", "Path", null);

 if (sugbdika.Equals("פולס"))
            {
                startInfo.FileName = FileName;
                startInfo.Arguments = Arguments;
            }
            else
            {
                startInfo.FileName = $"{_ExcelPathLocationStr}EXCEL.EXE ";
                startInfo.Arguments = "/x " + FileName + " " + Arguments;
            }
 Process p = Process.Start(startInfo);

The command line look like that :

startInfo.FileName => C:\\Program Files (x86)\\Microsoft Office\\Root\\Office16\\EXCEL.EXE startInfo.Arguments=> /x \\\\FILES\\~Departments\\tadWeb_reports\\Milenium.xltm /t/LE-15576/A/4/3.0/3.0 Actualy I want to open the \\FILES\~Departments\tadWeb_reports\Milenium.xltm file with this parameters string like /t/LE-15576/A/4/3.0/3.0

How can I do it by Excel Interop?

I have to try do

object oMissing = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Excel.Application oExcel = new Microsoft.Office.Interop.Excel.Application();

            oExcel.Visible = true;

            Microsoft.Office.Interop.Excel.Workbooks oBooks = oExcel.Workbooks;
            Microsoft.Office.Interop.Excel._Workbook oBook = null;

            oBook = oBooks.Open($"{startInfo.Arguments}", oMissing, oMissing,
                oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
                oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);

To use open on the next line : \\\\FILES\\~Departments\\tadWeb_reports\\Milenium.xltm /t/LE-15576/A/4/3.0/3.0

How can I do it?

1

1 Answers

0
votes

You are on the right avenue - the Workbooks.Open method opens a workbook. Most probably you will have to copy the file locally and then open it.

If you need to get command line arguments you can use the Environment.GetCommandLineArgs method which returns a string array containing the command-line arguments for the current process.

Application.Workbooks.Open(@"C:\Test\YourWorkbook.xlsx");

See How to: Programmatically open workbooks for more information.