M
Montana DOJ Help Desk
Word 2000
I have the code shown below. This code works as long as the current drive
is the same as the drive letter that is stored as part of the document
variable (which contains the full path to the folder where I want to store
the documnet). However, I have discovered a bug with this code. If the
current drive is DIFFERENT from the drive letter that is part of the
document variable, then the code blows up because ChDir does not change the
drive letter.
I've been reading in Help about ChDrive, GetAbsolutePathName, and
GetDriveName. With that information, I think that I'm close to solving this
problem, but I haven't been able to get it working yet, and I've run out of
time for tonight. Can some show me how I can get the current drive changed
so that it matches the drive letter from the full path name stored in the
document variable?
Sub FileSave()
Dim wdFileOpenDirectory As String
On Error GoTo ErrorHandler
' Stores the default directory for opening files, sets DocPath to the value
stored in the
' LocatesDocFullPath document variable, and then changes the default
directory. If the
' LocatesDocFullPath document variable does not exist, or if the variable
does exist, but
' contains the name of a folder that does not exist, then an error will be
generated and code
' execution will branch to ErrorHandler.
wdFileOpenDirectory = CurDir
DocPath = ActiveDocument.Variables("LocatesDocFullPath").Value
ChDir DocPath
' Saves the file as Locates.doc and restores the default file open directory
for Word.
ActiveDocument.SaveAs FileName:="Locates.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ChangeFileOpenDirectory wdFileOpenDirectory
Exit Sub
' Allows the user to specify the folder for the Locates document and saves
that folder path in the
' LocatesDocFullPath document variable.
ErrorHandler:
' If the folder name contained in DocPath does not exist (Error 76), or the
LocatesDocFullPath
' document variable does not exist (Error 5825), then the user is given the
opportunity to specify
' the path to Locates.doc.
If Err.Number = 76 Or Err.Number = 5825 Then
With Dialogs(wdDialogFileSaveAs)
.Name = "Locates.doc"
' If the Save button is clicked then the folder selected by the user
is stored in the
' LocatesDocFullPath document variable and in DocPath. Otherwise,
execution is halted.
If .Display = -1 Then
ActiveDocument.Variables("LocatesDocFullPath").Value =
CurDir
DocPath = CurDir
Else
End
End If
End With
End If
End Sub
-- Tom
State of Montana
Department of Justice Help Desk
"Making the world a safer place."
I have the code shown below. This code works as long as the current drive
is the same as the drive letter that is stored as part of the document
variable (which contains the full path to the folder where I want to store
the documnet). However, I have discovered a bug with this code. If the
current drive is DIFFERENT from the drive letter that is part of the
document variable, then the code blows up because ChDir does not change the
drive letter.
I've been reading in Help about ChDrive, GetAbsolutePathName, and
GetDriveName. With that information, I think that I'm close to solving this
problem, but I haven't been able to get it working yet, and I've run out of
time for tonight. Can some show me how I can get the current drive changed
so that it matches the drive letter from the full path name stored in the
document variable?
Sub FileSave()
Dim wdFileOpenDirectory As String
On Error GoTo ErrorHandler
' Stores the default directory for opening files, sets DocPath to the value
stored in the
' LocatesDocFullPath document variable, and then changes the default
directory. If the
' LocatesDocFullPath document variable does not exist, or if the variable
does exist, but
' contains the name of a folder that does not exist, then an error will be
generated and code
' execution will branch to ErrorHandler.
wdFileOpenDirectory = CurDir
DocPath = ActiveDocument.Variables("LocatesDocFullPath").Value
ChDir DocPath
' Saves the file as Locates.doc and restores the default file open directory
for Word.
ActiveDocument.SaveAs FileName:="Locates.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ChangeFileOpenDirectory wdFileOpenDirectory
Exit Sub
' Allows the user to specify the folder for the Locates document and saves
that folder path in the
' LocatesDocFullPath document variable.
ErrorHandler:
' If the folder name contained in DocPath does not exist (Error 76), or the
LocatesDocFullPath
' document variable does not exist (Error 5825), then the user is given the
opportunity to specify
' the path to Locates.doc.
If Err.Number = 76 Or Err.Number = 5825 Then
With Dialogs(wdDialogFileSaveAs)
.Name = "Locates.doc"
' If the Save button is clicked then the folder selected by the user
is stored in the
' LocatesDocFullPath document variable and in DocPath. Otherwise,
execution is halted.
If .Display = -1 Then
ActiveDocument.Variables("LocatesDocFullPath").Value =
CurDir
DocPath = CurDir
Else
End
End If
End With
End If
End Sub
-- Tom
State of Montana
Department of Justice Help Desk
"Making the world a safer place."