amrelgarhy81
asked on
Process.Start("EXCEL.EXE", filepath)
Hello,
Process.Start("EXCEL.EXE", filepath)
If filepath contain any spaces then the excel open in wrong way(say that the file is not exist).
Example:
"C:\Test App.xls" -----> fail
"C:\TestApp.xls" ------> success
Note:
Process.Start("IExplore.EX E", filepath)
works in any case.
How to solve that to make this line of code open the excel with the right file?
Process.Start("EXCEL.EXE",
If filepath contain any spaces then the excel open in wrong way(say that the file is not exist).
Example:
"C:\Test App.xls" -----> fail
"C:\TestApp.xls" ------> success
Note:
Process.Start("IExplore.EX
works in any case.
How to solve that to make this line of code open the excel with the right file?
Hi amrelgarhy81;
The Excel program takes the argument list and when it finds a space it thinks that the full file name has been given. So then following statement :
Visual Basic
Dim filepath As String = "C:\Test App.xls"
Process.Start("EXCEL.EXE", filepath)
C#
string filepath = @"C:\Test App.xls"
Process.Start("EXCEL.EXE", filepath)
Will try to open the files C:\test.xls and App.xls and not the file "Test App.xls. To correct the problem any time the filepath has spaces place " around the string like so
Visual Basic
Dim filepath As String = """C:\Test App.xls"""
Process.Start("EXCEL.EXE", filepath)
C#
string filepath = @"""C:\Test App.xls"""
Process.Start("EXCEL.EXE", filepath)
Excel will now see the filepath as "C:\Test App.xls"
Fernando
The Excel program takes the argument list and when it finds a space it thinks that the full file name has been given. So then following statement :
Visual Basic
Dim filepath As String = "C:\Test App.xls"
Process.Start("EXCEL.EXE",
C#
string filepath = @"C:\Test App.xls"
Process.Start("EXCEL.EXE",
Will try to open the files C:\test.xls and App.xls and not the file "Test App.xls. To correct the problem any time the filepath has spaces place " around the string like so
Visual Basic
Dim filepath As String = """C:\Test App.xls"""
Process.Start("EXCEL.EXE",
C#
string filepath = @"""C:\Test App.xls"""
Process.Start("EXCEL.EXE",
Excel will now see the filepath as "C:\Test App.xls"
Fernando
You can just skip the first parameter and then you don't need to worry about the quotes:
Process.Start(filepath)
Process.Start(filepath)
ASKER
I have a small problem in doing that:
the filepath came to the function as a parameter and i have no access to it.
Public Sub RunExcel(filepath)
Process.Start("EXCEL.EXE", filepath)
End Sub
the filepath came to the function as a parameter and i have no access to it.
Public Sub RunExcel(filepath)
Process.Start("EXCEL.EXE",
End Sub
???
Public Sub RunExcel(filepath)
Process.Start(filepath)
End Sub
You can't do that?
Public Sub RunExcel(filepath)
Process.Start(filepath)
End Sub
You can't do that?
ASKER
I can but i need to open a new instance of the excel so i need to do it like that:
Process.Start("EXCEL.EXE", filepath)
Process.Start("EXCEL.EXE",
Ok...put quotes around your filepath as both landerd and Fernando have already suggested.
Or...use the StartInfo() property of the process class:
Public Sub RunExcel(ByVal filepath)
Dim p As New Process
p.StartInfo.FileName = "Excel.exe"
p.StartInfo.Arguments = filepath
p.Start()
End Sub
Or...use the StartInfo() property of the process class:
Public Sub RunExcel(ByVal filepath)
Dim p As New Process
p.StartInfo.FileName = "Excel.exe"
p.StartInfo.Arguments = filepath
p.Start()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
string testpath = @"C:\test.xls";
System.Diagnostics.Process
testpath = @"""C:\test 1.xls""";
System.Diagnostics.Process