cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Martin
Level V

Can JMP launch an excel.xlsm file?

Is JMP jsl able to "launch" an Excel .xlsm (macro'ed) file, such that it essentially "double clicks" the file to open it and does not try to import it?

 

I am using an Excel macro for database extraction because it is 100X faster than the JMP ODBC extraction tool and would like my jsl code to run the macro'ed file.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Can JMP launch an excel.xlsm file?

Woops, I missed the file extension in the last line:

 

/* 	Function: openFileInOSDefault
		Open file in the operating system default program
		
		Include this once at the top of your script
		
	Arguments: 
		filepath - local path file
*/
openFileInOSDefault = Function({filepath},
	If( Host is( "Windows" ),
		Run Program(
			Executable( "PowerShell.exe" ),
			Options(
				Eval Insert( "\[-Command "& {Start-Process '^filepath^'}"]\" )
			),
			Read function( "text" )
		);
	,
		RunProgram(
			Executable( "/usr/bin/open" ),
			Options( filepath ),
			ReadFunction( "text" )
		)
	);
);

//Now in your script you can just call the function
openFileInOSDefault("C:\Users\Me\Desktop\test.xlsx")

View solution in original post

8 REPLIES 8
txnelson
Super User

Re: Can JMP launch an excel.xlsm file?

See the function

runprogram.PNG

in the Scripting Index

Jim
Martin
Level V

Re: Can JMP launch an excel.xlsm file?

Thanks @txnelson , but I am not sure this is the answer.  If I do not know where the "Excel.exe:" is kept on someone else's computer, how can I share my script with others?

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Can JMP launch an excel.xlsm file?

If you know everyone is on windows or has Powershell installed you can use Run Program to open the file using the default program defined by the OS:

 

Open a file in the operating system default program 

Martin
Level V

Re: Can JMP launch an excel.xlsm file?

Let's say I want to open a file called "Test.xlsx" that is located at "C:\Users\Me\Desktop\".  What would the code look like?

 

I have tried the following but it does not seem to work:

rp0 = Run Program(
	Executable( "Excel.EXE" ),
	Options("C:\Users\Me\Desktop\test"),
	Read Function("text")
);
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Can JMP launch an excel.xlsm file?

Give this a try:

 

/* 	Function: openFileInOSDefault
		Open file in the operating system default program
		
		Include this once at the top of your script
		
	Arguments: 
		filepath - local path file
*/
openFileInOSDefault = Function({filepath},
	If( Host is( "Windows" ),
		Run Program(
			Executable( "PowerShell.exe" ),
			Options(
				Eval Insert( "\[-Command "& {Start-Process '^filepath^'}"]\" )
			),
			Read function( "text" )
		);
	,
		RunProgram(
			Executable( "/usr/bin/open" ),
			Options( filepath ),
			ReadFunction( "text" )
		)
	);
);

//Now in your script you can just call the function
openFileInOSDefault("C:\Users\Me\Desktop\test")
Martin
Level V

Re: Can JMP launch an excel.xlsm file?

I get this error, thoughts?

 

"Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
At line:1 char:4
+ & {Start-Process 'C:\Users\Me\Desktop\test'}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

"

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Can JMP launch an excel.xlsm file?

Woops, I missed the file extension in the last line:

 

/* 	Function: openFileInOSDefault
		Open file in the operating system default program
		
		Include this once at the top of your script
		
	Arguments: 
		filepath - local path file
*/
openFileInOSDefault = Function({filepath},
	If( Host is( "Windows" ),
		Run Program(
			Executable( "PowerShell.exe" ),
			Options(
				Eval Insert( "\[-Command "& {Start-Process '^filepath^'}"]\" )
			),
			Read function( "text" )
		);
	,
		RunProgram(
			Executable( "/usr/bin/open" ),
			Options( filepath ),
			ReadFunction( "text" )
		)
	);
);

//Now in your script you can just call the function
openFileInOSDefault("C:\Users\Me\Desktop\test.xlsx")
Martin
Level V

Re: Can JMP launch an excel.xlsm file?

This is perfect and works like a charm!

 

@ih, thanks for your help.