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