Jump to content
Macro Express Forums

Challenge: a macro to open any file in WordPad (or in whatever program you want)

Recommended Posts

I have text files on my computer from a bygone era. Virtually all of the filenames have obsolete extensions such as...







Some of my files don't even have extensions. (My recollection is that filename extensions were optional during the MS-DOS age.)


Modern programs such as Word and WordPerfect don't recognize antediluvian file types and/or files without extensions. Ditto for basic text editors such as WordPad or NotePad. Every time I want to view my old files, I'm forced to do a song-and-a-dance, with far too many steps.


The challenge is to use Macro Express to create one hotkey macro for Windows 10 File Explorer. With any file selected, press the hotkey. The selected file opens in WordPad -- or in another program, if you prefer. The macro should open any file with any extension.




I experimented with different methods before I settled on a script that works reliably. So I'm so curious what other people come up with.


For bonus "points," find a solution that keeps focus on the most recently opened file in File Explorer. In other words, let's say you open the first file in a folder by pressing the hotkey. Close the file. Then press down arrow to select the second file in the folder and press the hotkey to open it. 

Link to comment
Share on other sites

You don't need a macro, just set the file extension association to whatever app you want to open it with. 

Settings > Apps > Default Apps > Choose default apps by file type.

Or you can double click the file, then select yoru app and check the box to "Always use this app..."

Link to comment
Share on other sites

I wouldn't have needed a macro had I taken the time to associate hundreds of file extensions. The files were created when one could choose almost any combination of letters, numbers, and symbols for the three-letter extension, including none. The macro circumvents the need to set up associations manually, or on-the-fly. Check out these extensions in a folder of files from 1993...






Although I made the macro to handle old files, I find it a handy way to open "modern" file types that I occasionally but rarely access, e.g.,





Link to comment
Share on other sites

First thing I would try is:


1) Right-click and rename the file appending whatever extension is desired:  filename.ext becomes filename.ext.xyz

2) Double-click the name or ENTER to open it with the xyz-associated application; or launch the application via the macro

3) Use a second macro to rename it back to the original after editing or whatever you want to do with the file


Might run into trouble with this, there may well be some hitch I'm not thinking of.

If all you want to do is look at the file, and don't plan to change and save it, the macro could copy it to a Temp folder/name with the xyz extension, and open it there. 

Link to comment
Share on other sites

1 hour ago, rberq said:

If all you want to do is look at the file, and don't plan to change and save it, the macro could copy it to a Temp folder/name with the xyz extension, and open it there. 


Copying the file and opening the copy is not what I did, but it's worth considering. Normally I open an old file, read it and/or copy something from it, and then exit without saving. I don't want to modify my old files.


So maybe this kind of logic?


1. Copy the selected file.

2. Paste the copy in a temporary folder.

3. Rename the copied file: append .txt or .rtf (or whatever) to the end of the file name.

4. Open the renamed file.

Link to comment
Share on other sites

Here's my solution.


1.    Open your "SendTo" folder.



Press Windows + R. This will bring up the "Run" dialog box. In the "Open" field, type:




Press Enter, or click the "OK" button. File Explorer will open the SendTo folder for your Windows account.


2. Ensure the SendTo folder includes a shortcut to WordPad.


If a shortcut to WordPad does not exist, navigate to this folder:


C:\Program Files\Windows NT\Accessories\


Scroll down to "wordpad.exe," make a shortcut, and move the shortcut to the SendTo folder.


Rename the shortcut "WordPad".

Suggestion: If there are other objects in the SendTo folder that start with the letter "W," rename them.


3. Create a new Macro Express script triggered by your hotkey of choice. Set the scope to Window/Program. Specify EXPLORER.EXE as the program.


4. Insert this code in the Script tab:


Text Type (Simulate Keystrokes): <APP>
Delay: 100 milliseconds
Text Type (Simulate Keystrokes): n
Delay: 100 milliseconds
Text Type (Simulate Keystrokes): w

<TEXT TYPE Action="0" Text="<APP>"/>
<DELAY Flags="\x02" Time="100"/>
<TEXT TYPE Action="0" Text="n"/>
<DELAY Flags="\x02" Time="100"/>
<TEXT TYPE Action="0" Text="w"/>


What it does: 1. Press the hotkey to open the context menu for the selected object; 2. Choose "Send to" from the context menu. 3. Choose "WordPad" from the submenu.

Link to comment
Share on other sites


Thank you, rberq!


Yet the approach you mentioned -- open a copy of the file rather than the original -- has merit, and I might try it.


I can tell you about an approach that I thought was promising. But I couldn't get it to work:


1. Extract the path to the selected file from the Address line: %Path%

2. Extract the name of the selected file through its properties: %FileName%

3. Use Macro Express to launch WordPad, with "%Path%\%FileName%" as its parameter.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...