I have an open Word document. When I hit CTRL+ALT+O on my keyboard, the folder that contains that document opens. This is very handy if I want to attach the open file to an email message by dragging and dropping the filename onto the message. It’s also very handy if there are other files in that folder that I want to open.
Tip: Always save your file before attaching it to an email message. If you attach without saving, only whatever portion that was already saved will be sent.
In my last post, I discussed four options for opening the containing folder of an open Word document. The first two required navigating the folder system. The third option required a little programming, and the fourth option (Office Tab) required $25.
For those who are interested in free option #3, here are the programming instructions courtesy of Tina Ostrander in my college’s Computer Science department. (Thanks, Tina!) The original code comes from the Code for Excel and Outlook blog. While it may look scary, it took less than 5 minutes to set it up.
**************************
Tina Ostrander writes:
In Word, select the View tab. Then Click Macros, View Macro… Type a Macro name, then click Create:
Copy this code:
Declare Function ShellExecute Lib “shell32.dll” Alias _
“ShellExecuteA” (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
Sub OpenContainingFolder()
On Error GoTo ErrorHandler
Dim currentDocPath As String
currentDocPath = ActiveDocument.Path
ShellExecute 0, “open”, currentDocPath, 0, 0, 1
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & ” – ” & Err.Description
Resume ProgramExit
End Sub
Into the macro window, like this [Note from Sue, highlight any existing code in the box, delete it, then paste in this code.]:
Click Save and close the window.
To run the macro, select Macro View Macros, and click Run. OR, you can assign a keyboard shortcut to the macro under File Options Customize Ribbon Keyboard Shortcuts: Customize. Scroll down to Macros on the left, select the OpenContainingFolder macro on the right, then select your keyboard shortcut. [Note from Sue: To choose your keyboard shortcut, click in the box labeled “Press new shortcut key,” then just press the keys you want to use. Tina pressed ALT+O, and you can see that in the screenshot below. I chose CTRL+ALT+O. If you choose a key combination that’s already in use, such as ALT+1, nothing will appear in the box. (ALT+1 activates whatever is in the first slot of your Quick Access Toolbar at the very top left corner of your Word window.)]
Click Assign, then Close, then OK.
**************************
That’s it! Open a Word document. Use your keyboard shortcut. The folder that contains that document will open.
I get an error after pasting the code to vb saying “Compile error: Expected: string constant” with “shell32.dll” highlighted. Pretty sure I followed the instructions to a t.
Thanks Sue!
David, I bet your computer is 64-bit, yes? I tried running the code on my new 64-bit laptop, and I got the same error. I emailed Tina O. who provided the original instructions, and she gave me this code that worked. Let me know if it works for you. — Sue
#If VBA7 Then
Private Declare PtrSafe Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#Else
Private Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If
Sub OpenContainingFolder()
On Error GoTo ErrorHandler
Dim currentDocPath As String
currentDocPath = ActiveDocument.Path
ShellExecute 0, “open”, currentDocPath, 0, 0, 1
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & ” – ” & Err.Description
Resume ProgramExit
End Sub
Hi Sue, thanks for replying!
Actually, my computer is 32-bit (Vista). I tried what you said anyway, but it didn’t work, still getting the same error.
Here’s what it looks like (using the original code):
http://img525.imageshack.us/img525/6002/errorjr.jpg
(that’s Hebrew).
Thanks again for trying to help!
David
Sorry for the slow reply! I’ve been traveling. Bummer. I really thought that would work. What version of Microsoft Office are you using?
No rush Sue, I have patience 🙂
Office 2007.
David, I’m afraid I’m out of guesses. For you, I recommend just getting Office Tab. See this post: http://suefrantz.com/2011/11/01/office-tab-added-functionality-for-word-excel-powerpoint/.
Sorry!
Thanks Sue, I downloaded Office Tab.
I’m getting another error now though… Quite frustrating.
When I right click the tab and choose Open Folder, it says: “OpenDir_Word does not exist, delete it or not?”
Whether I choose Yes or No, nothing happens.
This happened with every word document I tried.
Any clue?
Thanks,
David
Exact same problems as David. I’m using Office 2003, Win XP SP3.
Alternative solution didn’t work either.
If you’re getting an error message with Office Tab, please contact them at sales@extendoffice.com. They should be able to help.
Thanks, Sue, for this great tech tip. Had similar errors as those above and solved them with two changes – related to copy and paste and special characters. Here is what I did to make it work:
1. replace all “smart quotes” with “dumb” quotes – just delete the quote and type another quote – the quotes will change from slanty to non-slanty.
2. delete any extra line breaks after the _s at the end of lines. ( _ are code for continuing a single logical line of code on the next physical line in the editor)
3. (I also missed your note about deleting the existing code in the create new macro – so I had to do that too)
Hopefully this will help others get it working.
That totally worked John! Thanks! 🙂
Thanks for the help, John!