Create a reusable ODBC Exec file

If you frequently use File > Query Database (ODBC) to update your worksheet, you can automate the process with an Exec file.

Create the Exec file

  1. Import the data using File > Query Database (ODBC). For more information, go to Import data from a database by using ODBC.
  2. Press CTRL+K to open the History pane.
  3. Right-click in the History pane, then choose Save History As.
  4. Browse to the folder that you want to save your files in. In File name, enter Histogram.
  5. From Save as type, select Exec (*.mtb). Click Save.

The previous steps save all the commands in the History pane. To save just a few lines from the History pane, highlight them, and copy and paste into a text editor, such as Notepad. Then, save the file using a .mtb file extension.

Specify output columns in the Exec file

If you want to refresh the data in the same Minitab worksheet every time you run the Exec file, you need to edit the Exec file to specify the columns to use in the Minitab worksheet.

  1. In your text editor, such as Notepad, open the MTB file that you created.
  2. For each ODBC session command and corresponding subcommands, do the following:
    1. Replace the period (.) at the end of the final subcommand with a semi-colon (;), then press the Enter key.
    2. On the following line, specify the columns where you want to store the data. For example, enter Columns 1 2 3 4 5. To shorten sequential numbers, use a colon, for example Columns 1:5. If you define constants with integer values, you can enter lines like Columns k1 k2 k3 k4 k5., Columns k1:k5., or Columns 1:k5.
  3. Save your file and then close your text editor.


Connect "DSN=MS Access Database;DBQ=Q:\Mug\Mugmacro.mdb;
DefaultDir=Q:\Mug;DriverId=25;FIL=MS Access;
SQLString "SELECT 'City', 'Country', 'FirstName', 'LastName' FROM 'Authors'";
Columns 1 2 3 4.

Run the Exec file

  1. Choose File > Run an Exec.
  2. Specify the Number of times to execute.
  3. Click Select File.
  4. Select the Exec file that you saved, then click Open.