Windows – Associate a file type to a specific Excel workbook

microsoft excelwindows

I have a special extension (.dia) for storing electricity diagrams. Inside these files are binary, created by an Excel library (.xlam). For fast viewing of a diagram, I would like to bind the .dia extension to a specific Excel file (e.g. diagramViewer.xlsm), so that whenever I double click a .dia, this diagramViewer.xlsm opens up and reads the binary file (the path of which would most likely be passed as a command line argument) – is this possible?

Best Answer

I actually found a way to do this, however I haven't tested it. It dates back from my Windows 98 days, but it should work. I'm basing myself on this Microsoft DevNet post and on the workings of the command line as described by ss64.com.

1 - Accessing the file type.

To do this, open File Options. On Windows XP it's a matter of, on Explorer, clicking the Tools menu and then clicking File Options. On Vista/7, I'm basing myself on what is written here. Quoting:

Open Folder Options by clicking the Start button, clicking Control Panel, clicking Appearance and Personalization, and then clicking Folder Options.

Go to File Types and there find the .dia extension, as shown on here for a .bmp.

Folder Options - File Types

2 - Adding the command

Now press Advanced and then create a new action.

Advanced - Edit File Type New Action dialog

Write a name for the action (say Open in .dia and Excel). Now here's the catch: The file name is given as an optional argument called %1. Using the replacement syntax shown on the second link, in the "Application used to perform action" you should have something in the likes of the following:

excel "%1:.dia=.xlsm%"

This assumes the folder excel is at is at the %PATH% variable, which it should. Otherwise, just write the full path, inside " marks.This will supposedly replace the file extension from .dia to .xlsm. Some care is needed, as it will replace every instance of .dia for .xlsm. If you have a file name like some.diary.dia it will be replaced to some.xlsmry.xlsm.

This also means that the Excel file must have the same name as the .dia file.

You can make the action as default after you press OK by selecting the action you made and clicking on Set Default.

EDIT: I've written this based on the first impression that what the OP wanted to do was to open both the program that opened the .dia and excel. The answer is incomplete, as for it to be complete it would require a batch. However, I'm waiting for the OP's response.