Macro needed to insert a file chosen from a directory

M

Marley

Can anyone help me please? I need a macro which allows me to insert text from
whichever file I choose from a directory.

The idea is to click on a toolbar icon > display the folder containing the
text files > select the text file > Click to insert file. The trouble is I
could do it on my home PC but could not do it on my work network.

I used the macro from a previous post and it was great but I seem to have
trouble with the insert part of the macro and it includes both the S: path
and the C: temp path when asking me if I'm sure this is the file I want.

Macro used:
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


Thanks!
 
D

Doug Robbins - Word MVP

Try the following:

Dim fd As FileDialog
Dim FiletoInsert As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Title = "Select the File that you want to insert"
.InitialFileName = "S:\Insert\*.doc*"
.AllowMultiSelect = False
If .Show = -1 Then
FiletoInsert = .SelectedItems(1)
X = MsgBox("Are you sure that you want to insert " &
FiletoInsert & at the location of the selection?", vbYesNo + vbQuestion)
If X = vbYes Then
Selection.Range.InsertFile FiletoInsert
End If
End If
End With
Set fd = Nothing


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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