Open Explorer Window?

A

Andy

Is there code that I can use to open an Explorer Window displaying the
folder of the current open file?

TIA,

Andy
 
A

Andy

I want to assign a macro to a button to open an Explorer Window,
displaying the current Word document's folder.

Why doesn't this work?:


Sub OpenCurrentFolder()

Dim CurFold As String

CurFold = Application.ActiveWindow.Document.Path

Shell ("C:\WINDOWS\explorer.exe /e,CurFold"), (vbNormalFocus)

End Sub

Assume the current document is C:\A\myletter.doc. When I step through
the macro, CurFold is properly set to "C:\A" . I see it in the Locals
Window, and if I highlight it in the module window, the popup displays
CurFold = "C:\A" . But the Explorer Window opens to C:\. If I change


Shell ("C:\WINDOWS\explorer.exe /e,CurFold"), (vbNormalFocus)

to

Shell ("C:\WINDOWS\explorer.exe /e,C:\A"), (vbNormalFocus)


the macro opens an Explorer Window to C:\A, like I'd want if the
variable was working correctly. I'm wondering if the variable is
expanding with quotes, so there are extra quotes in the Shell
statement.

And ideas?

Andy
 
P

Peter

This is the correct syntax:
Call Shell("explorer.exe /e, " & CurFold, vbNormalFocus)

hth,

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top