Returning Path from wdDialogFileSaveAs

  • Thread starter Montana DOJ Help Desk
  • Start date
M

Montana DOJ Help Desk

Word 2000

I have the following routine that I'm developing. Please note that there
are bugs in this code, as I have not yet finished and tested it, but those
bugs shouldn't matter much for this particular question. For example, the
If IsError statement is not going to work as written because the On Error
GoTo ErrorHandler statement. But let's just ignore that little detail and
happily assume that all is well on that count. :) For now, I just want to
concentrate on what happens in ErrorHandler.

***************
Sub ErrorLogging()

Dim dlgAnswer As String
Dim ErrorLog As String
Dim FileNumber As Long
Dim FSO As Object

On Error GoTo ErrorHandler

FileNumber = FreeFile
Set FSO = CreateObject("Scripting.FileSystemObject")

ErrorLog = "Z:\Share\HelpDesk\Locates\Error.log"
If IsError(FSO.getFile(ErrorLog)) Then
Open ErrorLog For Output As FileNumber
Else
Open ErrorLog For Append As FileNumber
End If

Write #FileNumber, ErrDateTime, ModuleName, Subroutine, Err.Number,
Err.Context, Err.Description, Err.HelpFile, cbDataClip
Write #FileNumber,

Close #FileNumber
Exit Sub

ErrorHandler:

If Err.Number = 53 Then
dlgAnswer = Dialogs(wdDialogFileSaveAs).Show
ActiveDocument.Variables("ErrorLogPath").Value = dlgAnswer
End If
Resume

End Sub
***************

The path stored in ErrorLog will cause an error because there is no Z: drive
on my machine (This is done deliberately for testing purposes). The error
will cause code execution to jump down to ErrorHandler. My goal with
ErrorHandler is to let the user specify the path for the error log, and then
to save that path as a document variable (Eventually, this document variable
will be used to set the value of ErrorLog). The code in ErrorHandler works
splendidly for this purpose--IF the file happens to be the active document.
However, in this routine, the error log is NOT the active document, so the
code in ErrorHandler doesn't do the job.

How can I allow the user to specify the path to the error log, and then
capture the path value that is returned?

-- Tom

State of Montana
Department of Justice Help Desk

"Making the world a safer place."
 
C

Charles Maxson

Ok.... I may be out of turn here since I only tried this real quick in Word
2003, but I *think* this works:

Dialogs(wdDialogFileSaveAs).Display
ActiveDocument.Variables("ErrorLogPath").Value = CurDir

MsgBox ActiveDocument.Variables("ErrorLogPath").Value
 
M

Montana DOJ Help Desk

Yep! That works. I didn't know about the CurDir function. I was looking
in Help at the Path property, and also at the properties for the
wdDialogFileSaveAs dialog box. I guess that sometimes you just need to know
what to look for in order to find what you need.

Thanks for the help! Now I can concentrate on making the rest of the
routine work!

-- Tom

State of Montana
Department of Justice Help Desk

"Making the world a safer place."
 

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