Insert File - Location & Name

K

Kevin R

I have a macro that opens the Insert File dialog box to a default location
but I need to determine what the path or location is if the user changes the
"Look In" from the default and then determine what the selected file name is
so that it basically gives a prompt similar to "Are you sure you want to
insert " & sFileName & " and then delete it from " & sPath & "."

With Dialogs(wdDialogInsertFile)
.Name = "S:\Inserts"
End With
 
S

Steve Yandl

Kevin,

Try something like what I have below. Note, in the line
Options.DefaultFilePath(wdDocumentsPath) = "S:\Insert"
I've used mixed case in the path when changing the option. However, when
the option is read it is returned in all lower case which is why the path is
a bit different in my 'If' statement
If tempPath = "s:\insert" Then

Unlike the 'Show' method, the 'Display' method only displays the dialog box,
it doesn't automatically execute when the user clicks buttons. If the user
clicks the 'Insert' button, the method returns the value of -1, any other
method of closing the dialog box will return a different value and the
routine as written does nothing other than return the default document path
to what it was originally.

' ---------------------------------------------------

Sub MySpecFileInsert()
defPath = Options.DefaultFilePath(wdDocumentsPath)
Options.DefaultFilePath(wdDocumentsPath) = "S:\Insert"

Set myDialog = Dialogs(wdDialogInsertFile)

If myDialog.Display = -1 Then
tempPath = Options.DefaultFilePath(wdDocumentsPath)
If tempPath = "s:\insert" Then
myDialog.Execute
Else
x = MsgBox("Are you sure you want to insert " & tempPath _
& "\" & myDialog.Name, vbYesNo)
If x = 6 Then
myDialog.Execute
End If
End If
End If

Options.DefaultFilePath(wdDocumentsPath) = defPath
End Sub

' ---------------------------------------------------

Steve Yandl
 

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