Dialog Boxes Word

P

Paula

I am trying to get back a path to a selected file using
the following code, but can only get the filename.

Can anyone help?

Thanks

Sub GetFilePath()
Dim sFilename As String
Dim sFilePath As String
Dim dlgSaveAs As Dialog

Set dlgSaveAs = Dialogs(wdDialogFileOpen)
dlgSaveAs.Display
sFilename = dlgSaveAs.Name
sFilePath = dlgSaveAs.????

MsgBox sFilePath & "\" & sFilename

End Sub
 
D

Dave Lett

Hi Paula

It looks like you're trying to return the fullname of the file that you've selected. If so, then you can use the following to do that

Sub GetFilePath(
Dim sFullName As Strin
Dim dlgSaveAs As Dialo
Dim f

Set dlgSaveAs = Dialogs(wdDialogFileOpen
With dlgSaveA
.Displa
Set fs = CreateObject("Scripting.FileSystemObject"
sFullName = fs.GetAbsolutePathName(Replace(.Name, Chr(34), "")
End Wit

MsgBox sFullNam
End Su


HTH
Dave
 
C

Cindy M -WordMVP-

Replied to duplicate question in another group
(docmanagement, maybe?)

Cindy Meister
 
P

Perry

You almost had it :))

Dim sFilename As String
Dim sFilePath As String
Dim dlgSaveAs As Dialog

Set dlgSaveAs = Dialogs(wdDialogFileOpen)
dlgSaveAs.Display
sFilename = dlgSaveAs.Name
sFilePath = CurDir

MsgBox sFilePath & "\" & Replace(sFilename, Chr(34), "")


CurDir returns the current directory/path.
Replace() is used to eliminate the Double quotes in case the filename
as returned from dlgSaveAs.Name, includes a space(s).

Krgrds,
Perry
 
B

beata

Replace doesn't work for Word 97 :( Do you know an similar thing. Rest
of code works fine.

ciao
 
M

Martin Seelhofer

Hi there
Replace doesn't work for Word 97 :( Do you know an similar thing. Rest
of code works fine.

Here's code which simulates the replace functionality:

Function MyReplace(ByVal txt As String, fnd As String, rpl As String) As
String
Dim pos As Integer
' replace first occurence of text fnd until no occurence found
Do
pos = InStr(1, txt, fnd)
If pos = 0 Then Exit Do

txt = Left(txt, pos - 1) + rpl + Mid(txt, pos + Len(fnd))
Loop
MyReplace = txt
End Function

Note, that I used another name to prevent confusion with the built-in
Replace-function of later versions of Office-VBA. The usage, however,
is the same:

.... MyReplace( myTextHere, vbCrLf, vbCr) & " "


Cheers,
Martin
 

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