Sunday, May 14, 2017

Command-line switches for Excel

Command-line switches for Excel

This article shows you how to customize the way that Microsoft Office Excel 2007 starts by adding switches and parameters to the startup command. For example, you can prevent the startup screen from appearing when you start Office Excel 2007, or you can have Excel open a specific file when it starts.

Command line switches are also called command-line options, and sometimes you can use a parameter without a switch.

If you want to use a switch and any associated parameters just one time, you can type the command in the Run dialog box (Start menu) in Microsoft Windows. If you want to use the same switch and associated parameters many times, you can create a desktop shortcut that always starts the program by using the same switch and parameters. This article discusses how to do both, and contains a table that lists all of the switches and parameters that are available in Office Excel 2007.

In this article

Introducing commands, switches, and parameters

Use a switch once by adding it to the Run command

Make a switch available for reuse by creating a shortcut

Available switches and parameters

Introducing commands, switches, and parameters

Each time that you start Excel 2007 by clicking the Excel program icon or the program name on the Start menu, you are actually running the Excel.exe command, although you do not usually type the command or even see it.

You can change certain aspects of how the program starts by adding subcommands called switches to the Excel.exe command. A switch appears as a space after the main command, followed by a slash mark (/) and the name of the switch. The switch is sometimes followed by another space and then one or more specific instructions called parameters, which give the program further information about how to execute the Excel.exe command. For example, the following command instructs Excel to start and then open the specified file as read-only:

excel.exe /r "c:\My Folder\book1.xlsx"

In this example, the switch is /r, and the parameter is "c:\My Folder\book1.xlsx".

Top of Page

Use a switch once by adding it to the Run command

  1. In Microsoft Windows, click the Start button, and then click Run.

    Note: If you are running Windows Vista and you click the Start button Button image and do not see the Run command, point to All Programs, click Accessories, and then click Run.

  2. In the Run dialog box, type excel.exe, or click Browse to locate it.

  3. Type a space, and then type the switch and any parameters. For example, to start Excel without displaying the startup screen and without opening a blank workbook, you would type:

    excel.exe /e

The next time that you start Excel, the program will start according to its defaults (without making use of the switch that you just provided). To make your customized startup available for repeated uses, see the following section.

Note: 

  • Switches and parameters are not case-sensitive. For example, /R is the same as /r.

  • Remember to include one blank space before the switch and one before each parameter.

Top of Page

Make a switch available for reuse by creating a shortcut

First, verify the location of the Excel.exe file on your computer. If you accepted the default folder locations when you installed Excel, the Excel.exe file is probably located at:

C:\Program Files\Microsoft Office\Office12\Excel.exe

If you do not find the Excel.exe file at that location, search for the file and make a note of the full path.

  1. Right-click the Windows desktop, point to New, and then click Shortcut on the shortcut menu.

  2. In the Create Shortcut Wizard, in the Type the location of the item box, type a quotation mark ("), enter the full path for the Excel.exe file (including the file name), and then type a quotation mark. (Alternatively, click Browse to locate and select the file. In this case, the quotation marks are added automatically.)

  3. Following the closing quotation mark, type a space, and then type the switch and any parameters. If the parameter is a path to a location on your computer, and the path contains a space, it also must be enclosed in quotation marks. For example:

"c:\program files\microsoft office\office12\excel.exe" /r "c:\My Folder\book1.xlsx"

  1. Click Next.

  2. In the Type a name for this shortcut box, type a name for the shortcut, and then click Finish.

    The wizard creates the shortcut and places it on the desktop.

  3. Whenever you want to start Excel in this particular customized way, double-click the shortcut.

    Tip: To add the desktop shortcut to the Windows Start menu, right-click the shortcut, and then click Pin to Start menu on the shortcut menu.

You can create a variety of shortcuts, each of which applies different switches and parameters to the program at startup.

Note: 

  • Switches and parameters are not case-sensitive. For example, /R functions the same as /r.

  • Remember to include one blank space before the switch and one before each parameter.

Top of Page

Available switches and parameters

The following table lists all of the switches and parameters that are available in Office Excel 2007.

Switch and parameter

Description

workbook path | file name

This parameter does not require a switch.

Starts Excel and opens the specified file.

Example

excel.exe "c:\My Folder\book1.xlsx"

or

excel.exe http://MySite/Book1.xlsx

/r workbook path | file name

Opens a specific workbook as read-only.

Example

excel.exe /r "c:\My Folder\book1.xlsx"

or

excel.exe /r http://MySite/Book1.xlsx

/t workbook path | file name

Starts Excel and opens the specified file as a template.

Example

excel.exe /t "c:\My Folder\book_name.xlsx".

or

excel.exe /t http://MySite/book_name.xlsx

/n workbook path | file name

Like /t, starts Excel and opens the specified file as a template.

Example

excel.exe /n "c:\My Folder\book_name.xlsx".

or

excel.exe /n http://MySite/book_name.xlsx

/e or /embed

Prevents the Excel startup screen from appearing and a new blank workbook from opening.

Example

excel.exe /e

/p workbook path

Specifies a folder as the active working folder (for example, the folder that is pointed to in the Save As dialog box).

Example

excel.exe /p "c:\My Folder"

/s or /safemode

Forces Excel to bypass all files that are stored in startup directories, such as the default XLStart folder located in the directory where Excel or the 2007 Microsoft Office system is installed.

Example

excel.exe /s

/m

Creates a new workbook that contains a single XLM macro sheet.

Example

excel.exe /m

/a progID

Starts Excel and loads the Automation Addin that is specified by the progID of the add-in.

Example

excel.exe /a MyProgId.MyProgID2.1

Top of Page


2 comments: