Show Folder index list in word document

L

lorne17

Hello there,

I am trying to figure out if it is possible to place a folder index
list or table of contents showing the files in a specific folder. We
have a folder full of video tutorials and would like to have a word doc
that shows these files in a list. But if we add a video we want that
list to update automatically.

And if that isn't enough, can I have them linked so when clicked I can
view it?

thanks,
Lorne
 
L

lorne17

I'm lost on what that link is showing? It's all coding and well I don't
know WORD coding. Any other methods on how to do this? Thanks for the
help.

Lorne

PS-What does this mean: "Please reply to the newsgroup unless you wish
to avail yourself of my services on a paid consulting basis"
 
D

Doug Robbins - Word MVP

See the article "What do I do with macros sent to me by other newsgroup
readers to help me out?" at:

http://www.word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

Reur PS, it means that you should reply to the newsgroup with any additional
questions UNLESS you wish to engage me to provide assistance to you
personally on a pay for hire basis. My contributions to the newsgroups are
free.


--
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
 
L

lorne17

Ok,

This worked great. But is there a way to have this list updated
automatically? It is really what we're needing.

Thanks,

Lorne
 
D

Doug Robbins - Word MVP

It can only be updated by deleting the existing list and running the macro
again. How automatic do you need to make it?

While you could create a macro that ran automatically when the document was
opened, there must be some way of identifying the location of the existing
list so that the macro can delete it and replace it.

One way would be to have the list created inside a one cell table (without
borders if desired)

If that table was the first table in the document, adding the following code
at the beginning of the macro would delete the contents of that table and
replace it with an updated list

ActiveDocument.Tables(1).Cell(1, 1).Select
Selection.Delete

I would recommend that you save this document as a template, and create the
macro in the template and change its name to Sub Autonew()

Then when you create a document from that template, the list will be updated
each time.

--
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
 
L

lorne17

Ok,

Adding the new code to the macro worked. A couple issues though:

-It's not automatic when I open the file. How do I make it automatic?
-How can I change my coding to automatically select a folder path? Not
have the user select it (our folder location won't be changing).
-Also, can I have this list be linked to each individual file? That
way if the user clicks the name of the file, it will open that file.
-Have a set font/size for list? (is this part of the macro coding?)

Am I asking to much? It would be really nice for this to be this way
and not have to worry about it for future users in this file.

Thanks so much for your help and patience.

Lorne
 
D

Doug Robbins - Word MVP

Like I said, I would recommend that you save this document as a template,
and create the
macro in the template and change its name to Sub Autonew()

Then when you create a new document from that template, the macro will run.

To hard code the folder location, replace

'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

with

MyPath = "Drive:\Folder\"

If you save the document as a template as I recommend, then you could also
have a macro in that template that opened the selected file

Dim myfile As String

myfile = Selection.Paragraphs(1).Range.Text
Documents.Open "Drive\Folder\" & myfile

Where "Drive\Folder\" are the same as used in the code above.

To apply a particular font, use

With ActiveDocument.Tables(1).Cell(1, 1).Range.Font
.Name = "Arial"
.Size = 10
End With

Change the name of the font and the size to those that take your fancy.

--
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
 
L

lorne17

I am so sorry to keep bothering you on this matter. I really appreciate
the help.

I tried replacing that code with: MyPath = "Drive:\Folder\"

But it doesn't work. When I place my path in there, it runs the macro
with no errors and acts as if it's working, and flashes the highlighted
selection in my table. But doesnt' insert any file names? Any reason
why this is?

This is what I have:
Sub Autonew()

ActiveDocument.Tables(1).Cell(1, 1).Select
Selection.Delete

Dim MyPath As String
Dim MyName As String

MyPath = "O:\Detail-Standards\Revit How To\Video Tutorials"

'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
Selection.InsertAfter MyName & vbCr
MyName = Dir
Loop

'collapse the selection
Selection.Collapse wdCollapseEnd

With ActiveDocument.Tables(1).Cell(1, 1).Range.Font
.Name = "Arial"
.Size = 10
End With

End Sub

With that said, what is wrong with it? Anything you see?

Also, regarding your suggestion for making this a template file. We'll
never need to use this macro on another file. I just wanted it to run
when I open the current document not a new document with this template
file. Does that make sense?

Also what's the code to make the font bold? I tried: .Style = Bold.
Didn't work :p

I assume, there is no way to make the file names in the list links to
each individual file?

Thanks again!! You really are a HUUUGE HELP :)

Lorne
 
D

Doug Robbins - Word MVP

This line of code:

MyPath = "O:\Detail-Standards\Revit How To\Video Tutorials"

should be:

MyPath = "O:\Detail-Standards\Revit How To\Video Tutorials\"

That is, it must terminate in a path separator \
--
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
 
L

lorne17

Awesome thanks for the help. I figured out the bold too:

.Bold = True

I think we have it to our liking. If anyone knows how to make i
automatic upon opening that would be best.

Thanks for the patience and help.

Lorne
 
Top