0

Countless times a day, I go into Windows Explorer, shift-right click on an Excel file, Copy as path, then go into Run, type Excel /r (paste), which opens my Excel file as read only.

Is there a way to record all this (and similar routine tasks) in a macro, so that I could easily open these files this way? E.g. Shift-Enter opens the file as an Excel read only, as in the mechanism above?

Loosely related to How can I open a file as read-only from Windows Explorer?

Eliyahu
  • 584

1 Answers1

4

Autohotkey is definitely the way to go here.

As long as you're Shift-rightclicking, though, why not just Open as Read-Only? enter image description here

edit: as mentioned below, it doesn't work (?!?).

Back to my original suggestion. Autohotkey can record you doing this with the ScriptWriter module, which you can then tweak. You'll probably end up with something like:

IfWinActive, ahk_class XLMAIN ^B:: ; hotkey is CTRL + B but can be changed to anything ExcelFileName := "C:\path\to\file.xlsx" ; this needs to be replaced with a variable Send, {LWINDOWN}r{LWINUP} ;opens Run WinWaitActive, Run, Send, excel{SPACE}/r{SPACE}ExcelFileName{Enter}

If you tell me more about how your files are stored (any naming conventions? etc) I can help you get the path into the hotkey. Without that all I can come up with is a nasty VBA -> AHK kludge from within the Excel file you want, like

Sub GetPath() Dim CompletePath As String CompletePath = ActiveWorkbook.FullName MsgBox CompletePath End Sub

which you could then dump into the AHK script as ExcelFileName.

edit 2: I think with the desired Excel file highlighted Send {Ctrl Down}c{Ctrl Up} will copy the file path into the Clipboard, which you could then pass in as ExcelFileName := %clipboard%.

Try this. Highlight your file and hit CTRL + B.

^B:: ; hotkey is CTRL + B but can be changed to anything Send {Ctrl Down}c{Ctrl Up} ; copies path to Clipboard (unverified) ExcelFileName := %clipboard% ; plaintext Send, {LWINDOWN}r{LWINUP} ; opens Run WinWaitActive, Run, Send, excel{SPACE}/r{SPACE}ExcelFileName{Enter}

meatspace
  • 1,153