Word Hacks [Electronic resources]

Andrew Savikas

نسخه متنی -صفحه : 162/ 27
نمايش فراداده

2.5 Quickly Change Your File Open Path

Instead of always using My Documents, this hack shows you how to make Word open to the folder where your documents really are.

Few Word workers keep all their files in the My Documents folder. Much of the time they're on your desktop or in a different project folder deep on your hard drive. Sometimes they're not even "your" documents; they may live on a server across the office, or across the country. But when you want to get to one of those files, choosing FileOpen always sends you to the same place: the My Documents folder.

Though you can change this default settingWord will open to the folder of your choosingit involves a long trip through ToolsOptionsFile LocationsModify. You must then do some more mouse work as you browse for the folder you want to use. Many users give up and resign themselves to starting each workday with a trip through My Documents, but a short macro provides an easier way.

2.5.1 The Code

This macro provides an interactive way to change the FileOpen folder to the folder in which the current document resides. Create the following macro, named ReAssignFileOpen, in the template of your choice [Hack #50] :

Sub ReAssignFileOpen( )
Dim sNewPath As String
Dim sCurrentPath As String
Dim sDefaultPath As String
Dim lResponse As Long
sNewPath = ActiveDocument.Path
' Current document must have been saved
' at least once to be in a folder
If Len(sNewPath) = 0 Then
MsgBox "Please save this document first.", vbExclamation
Exit Sub
End If
' Capture the default path by temporarily resetting the current one
sCurrentPath = Options.DefaultFilePath(wdDocumentsPath)
Options.DefaultFilePath(wdDocumentsPath) = "
sDefaultPath = Options.DefaultFilePath(wdDocumentsPath)
' Restore to the current path
Options.DefaultFilePath(wdDocumentsPath) = sCurrentPath
' Prompt user to confirm change to current document's folder
lResponse = MsgBox("Really Change File...Open path to:" & _
vbCr & vbCr & _
sNewPath & "?" & _
vbCr & vbCr & _
"Press Cancel to reset to Default (" & sDefaultPath & ").", _
vbYesNoCancel)
' Process response
Select Case lResponse
Case Is = vbYes
Options.DefaultFilePath(wdDocumentsPath) = sNewPath
Case Is = vbNo
Exit Sub
Case Is = vbCancel
Options.DefaultFilePath(wdDocumentsPath) = sDefaultPath
End Select
End Sub

2.5.2 Running the Hack

When you run this macro, you'll be prompted with the dialog shown in Figure 2-13, asking you to confirm the change. If you select Yes, the next time you choose FileOpen, Word will place you in the chosen folder.

If you point this setting to a folder on a network drive and select FileOpen while no longer connected to the network, Word will return to its default FileOpen folder (usually My Documents).

Figure 2-13. Changing FileOpen to default to the current document's folder

For quick access to this timesaver, put a button for it on the Standard toolbar [Hack #1] or add it to the File menu [Hack #3].

2.5.3 See Also

[Hack #57]