Insert file - shortcuts

J

JayM

i have a folder which is referenced in a global constant (varUSERTEXT)

This following code works fine if the text entered into the Inputbox is an
actual word document. If the text entered is for a shortcut to then it
errors. What I wanted to do was tidy the folder up for each department so
they could browse to the folder if needs be (using a userform rather than an
input box) but if they know the filename just enter it without having any
other input. hence I would have a shortcut reference in varUSERTEXT

Sub InsertText()
' Inserts User Texts
On Error GoTo errhandler
resultx = InputBox("Please enter the name of the Text Segment you wish
to use :", "Enter Short Text")
If resultx = "" Then Exit Sub
resulty = Dir(varUSERTEXT & resultx & ".DOC", vbArchive + vbHidden +
vbNormal + vbReadOnly + vbSystem)
If resulty = "" Then
MsgBox "Sorry, but '" & resultx & "' is NOT a valid Text Segment.
Please Try Again .....", vbCritical, resultx & " : NOT FOUND !"
Exit Sub
End If
Selection.InsertFile FileName:=varUSERTEXT & resultx & ".DOC",
Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False

Exit Sub
errhandler:
MsgBox "Sorry, but '" & resultx & "' is NOT a valid Text Segment.
Please Try Again .....", vbCritical, resultx & " : NOT FOUND !"
End Sub
 
G

Graham Mayor

Try a different approach

Sub InsertText()
Dim strFilename As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.Title = "Select Text Segment File"
.InitialFileName = varUSERTEXT
.Filters.Add "Word Documents", "*.doc", 1
.AllowMultiSelect = False
If .Show <> -1 Then
MsgBox "Cancelled By User", , _
"List Folder Contents"
Exit Sub
End If
strFilename = .SelectedItems(1)
End With
Selection.InsertFile strFilename
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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