From: JayM on
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

From: Graham Mayor on
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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"JayM" <JayM(a)discussions.microsoft.com> wrote in message
news:F1346262-BC1B-4397-9C4F-AC5B6F82A31F(a)microsoft.com...
>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
>


From: JayM on
Hi thanks graham

Not exactly what I was after but another way around it.

JayM

"Graham Mayor" wrote:

> 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
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> "JayM" <JayM(a)discussions.microsoft.com> wrote in message
> news:F1346262-BC1B-4397-9C4F-AC5B6F82A31F(a)microsoft.com...
> >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
> >
>
>
> .
>