Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
DebPgh DebPgh is offline
external usenet poster
 
Posts: 3
Default Macro for Listing Files in a Folder

Hi,

In the Microsoft Knowledge Base articles, there is a wonderful macro that
enables you to list all of the files in a particular folder (Article
ID:306248, WD2002: Sample Macro to List All Files in a Folder). It was
designed for Word 2002, but it also works in Word 2003. However, it doesn't
work in Word 2007. When run, the macro says there are no files in the folder
even though there are files.

Can anyone tell me what changes to make so that this macro will work? Or is
there another macro somewhere or some other process that will allow me to
list the files in a folder (along with the file size and last modified date
and time)?

Thanks in advance for your help.

  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Macro for Listing Files in a Folder

The routine used to list the folder content does not work in 2007 as you
have found. Rather than rewrite the macro to use an alternative routine, use
the free and rather more powerful PrintFolders utility that you can download
from my web site instead.

--

Graham Mayor - Word MVP

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



DebPgh wrote:
Hi,

In the Microsoft Knowledge Base articles, there is a wonderful macro
that enables you to list all of the files in a particular folder
(Article ID:306248, WD2002: Sample Macro to List All Files in a
Folder). It was designed for Word 2002, but it also works in Word
2003. However, it doesn't work in Word 2007. When run, the macro
says there are no files in the folder even though there are files.

Can anyone tell me what changes to make so that this macro will work?
Or is there another macro somewhere or some other process that will
allow me to list the files in a folder (along with the file size and
last modified date and time)?

Thanks in advance for your help.



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
DebPgh DebPgh is offline
external usenet poster
 
Posts: 3
Default Macro for Listing Files in a Folder

Graham,

Thanks for your suggestion. The two websites you referred me to look like
they have a lot of good info.

The problem is that I need this capability for my office computer. Our
company won't let us download any programs from the Internet. Using a macro
was a good way to get around this problem.

Deb

"Graham Mayor" wrote:

The routine used to list the folder content does not work in 2007 as you
have found. Rather than rewrite the macro to use an alternative routine, use
the free and rather more powerful PrintFolders utility that you can download
from my web site instead.

--

Graham Mayor - Word MVP

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



DebPgh wrote:
Hi,

In the Microsoft Knowledge Base articles, there is a wonderful macro
that enables you to list all of the files in a particular folder
(Article ID:306248, WD2002: Sample Macro to List All Files in a
Folder). It was designed for Word 2002, but it also works in Word
2003. However, it doesn't work in Word 2007. When run, the macro
says there are no files in the folder even though there are files.

Can anyone tell me what changes to make so that this macro will work?
Or is there another macro somewhere or some other process that will
allow me to list the files in a folder (along with the file size and
last modified date and time)?

Thanks in advance for your help.




  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Macro for Listing Files in a Folder

Perhaps you could ask your IT support to check it out?

In the meantime

Sub ListFolder()
Dim TargetDoc As Document
Dim fDialog As FileDialog
Dim sPath As String
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder to list and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
sPath = fDialog.SelectedItems.Item(1) & Chr(92)
End With
On Error Resume Next
Set TargetDoc = Documents.Add
Selection.TypeText "File Listing of the """ & sPath & """ Folder" & vbCr &
vbCr
sName = Dir$(sPath)
Do While sName ""
Selection.TypeText sName & vbCr
sName = Dir$
Loop
End Sub

will give you a filename listing for a selected folder.

--

Graham Mayor - Word MVP

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



DebPgh wrote:
Graham,

Thanks for your suggestion. The two websites you referred me to look
like they have a lot of good info.

The problem is that I need this capability for my office computer.
Our company won't let us download any programs from the Internet.
Using a macro was a good way to get around this problem.

Deb

"Graham Mayor" wrote:

The routine used to list the folder content does not work in 2007 as
you have found. Rather than rewrite the macro to use an alternative
routine, use the free and rather more powerful PrintFolders utility
that you can download from my web site instead.

--

Graham Mayor - Word MVP

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



DebPgh wrote:
Hi,

In the Microsoft Knowledge Base articles, there is a wonderful macro
that enables you to list all of the files in a particular folder
(Article ID:306248, WD2002: Sample Macro to List All Files in a
Folder). It was designed for Word 2002, but it also works in Word
2003. However, it doesn't work in Word 2007. When run, the macro
says there are no files in the folder even though there are files.

Can anyone tell me what changes to make so that this macro will
work? Or is there another macro somewhere or some other process
that will allow me to list the files in a folder (along with the
file size and last modified date and time)?

Thanks in advance for your help.



  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey[_2_] Greg Maxey[_2_] is offline
external usenet poster
 
Posts: 668
Default Macro for Listing Files in a Folder

Graham,

I have no doubt that you answered the OP which I didn't read. You can get a
lot of additional information using the FileSystemObject (requires reference
to Microsoft Scripting Runtime):

Option Explicit
Dim arrFiles() As String
Dim i As Long
Sub ListFolder()
Dim TargetDoc As Document
Dim fDialog As FileDialog
Dim sPath As String
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder to list and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
sPath = fDialog.SelectedItems.Item(1) & Chr(92)
End With
arrFiles = GetFileNames(sPath)
On Error Resume Next
Set TargetDoc = Documents.Add
With TargetDoc.Range
.Font.Size = 8
.InsertAfter "File Listing of the """ & sPath & """ Folder" & vbCr & vbCr
For i = 0 To UBound(arrFiles, 2)
.InsertAfter "File name: " & arrFiles(0, i) & vbTab & "Size: " _
& arrFiles(1, i) & vbTab & "Type: " & arrFiles(2, i) _
& vbTab & "Last Modified: " & arrFiles(3, i) & vbCr & vbCr
Next i
End With
End Sub
Function GetFileNames(ByRef pFolder As String) As String()
Dim fso As New FileSystemObject
Dim oFld As Folder
Dim oFile As File
i = 0
If fso.FolderExists(pFolder) Then
Set oFld = fso.GetFolder(pFolder)
For Each oFile In oFld.Files
ReDim Preserve arrFiles(3, i)
arrFiles(0, i) = oFile.Name
arrFiles(1, i) = oFile.Size
arrFiles(2, i) = oFile.Type
arrFiles(3, i) = oFile.DateLastModified
i = i + 1
Next
GetFileNames = arrFiles
End If
End Function


Graham Mayor wrote:
Perhaps you could ask your IT support to check it out?

In the meantime

Sub ListFolder()
Dim TargetDoc As Document
Dim fDialog As FileDialog
Dim sPath As String
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder to list and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
sPath = fDialog.SelectedItems.Item(1) & Chr(92)
End With
On Error Resume Next
Set TargetDoc = Documents.Add
Selection.TypeText "File Listing of the """ & sPath & """ Folder" &
vbCr & vbCr
sName = Dir$(sPath)
Do While sName ""
Selection.TypeText sName & vbCr
sName = Dir$
Loop
End Sub

will give you a filename listing for a selected folder.


DebPgh wrote:
Graham,

Thanks for your suggestion. The two websites you referred me to look
like they have a lot of good info.

The problem is that I need this capability for my office computer.
Our company won't let us download any programs from the Internet.
Using a macro was a good way to get around this problem.

Deb

"Graham Mayor" wrote:

The routine used to list the folder content does not work in 2007 as
you have found. Rather than rewrite the macro to use an alternative
routine, use the free and rather more powerful PrintFolders utility
that you can download from my web site instead.

--

Graham Mayor - Word MVP

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



DebPgh wrote:
Hi,

In the Microsoft Knowledge Base articles, there is a wonderful
macro that enables you to list all of the files in a particular
folder (Article ID:306248, WD2002: Sample Macro to List All Files
in a Folder). It was designed for Word 2002, but it also works in
Word 2003. However, it doesn't work in Word 2007. When run, the
macro says there are no files in the folder even though there are
files. Can anyone tell me what changes to make so that this macro will
work? Or is there another macro somewhere or some other process
that will allow me to list the files in a folder (along with the
file size and last modified date and time)?

Thanks in advance for your help.


--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org

McCain/Palin '08 !!!




  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Macro for Listing Files in a Folder

It falsl over at
Set oFld = fso.GetFolder(pFolder)
even with Microsoft ScriptingRuntime. I have a feeling I am missing
something here

--

Graham Mayor - Word MVP

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



Greg Maxey wrote:
Graham,

I have no doubt that you answered the OP which I didn't read. You
can get a lot of additional information using the FileSystemObject
(requires reference to Microsoft Scripting Runtime):

Option Explicit
Dim arrFiles() As String
Dim i As Long
Sub ListFolder()
Dim TargetDoc As Document
Dim fDialog As FileDialog
Dim sPath As String
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder to list and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
sPath = fDialog.SelectedItems.Item(1) & Chr(92)
End With
arrFiles = GetFileNames(sPath)
On Error Resume Next
Set TargetDoc = Documents.Add
With TargetDoc.Range
.Font.Size = 8
.InsertAfter "File Listing of the """ & sPath & """ Folder" & vbCr &
vbCr For i = 0 To UBound(arrFiles, 2)
.InsertAfter "File name: " & arrFiles(0, i) & vbTab & "Size: " _
& arrFiles(1, i) & vbTab & "Type: " & arrFiles(2, i) _
& vbTab & "Last Modified: " & arrFiles(3, i) & vbCr & vbCr
Next i
End With
End Sub
Function GetFileNames(ByRef pFolder As String) As String()
Dim fso As New FileSystemObject
Dim oFld As Folder
Dim oFile As File
i = 0
If fso.FolderExists(pFolder) Then
Set oFld = fso.GetFolder(pFolder)
For Each oFile In oFld.Files
ReDim Preserve arrFiles(3, i)
arrFiles(0, i) = oFile.Name
arrFiles(1, i) = oFile.Size
arrFiles(2, i) = oFile.Type
arrFiles(3, i) = oFile.DateLastModified
i = i + 1
Next
GetFileNames = arrFiles
End If
End Function


Graham Mayor wrote:
Perhaps you could ask your IT support to check it out?

In the meantime

Sub ListFolder()
Dim TargetDoc As Document
Dim fDialog As FileDialog
Dim sPath As String
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder to list and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
sPath = fDialog.SelectedItems.Item(1) & Chr(92)
End With
On Error Resume Next
Set TargetDoc = Documents.Add
Selection.TypeText "File Listing of the """ & sPath & """ Folder" &
vbCr & vbCr
sName = Dir$(sPath)
Do While sName ""
Selection.TypeText sName & vbCr
sName = Dir$
Loop
End Sub

will give you a filename listing for a selected folder.


DebPgh wrote:
Graham,

Thanks for your suggestion. The two websites you referred me to
look like they have a lot of good info.

The problem is that I need this capability for my office computer.
Our company won't let us download any programs from the Internet.
Using a macro was a good way to get around this problem.

Deb

"Graham Mayor" wrote:

The routine used to list the folder content does not work in 2007
as you have found. Rather than rewrite the macro to use an
alternative routine, use the free and rather more powerful
PrintFolders utility that you can download from my web site
instead. --

Graham Mayor - Word MVP

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



DebPgh wrote:
Hi,

In the Microsoft Knowledge Base articles, there is a wonderful
macro that enables you to list all of the files in a particular
folder (Article ID:306248, WD2002: Sample Macro to List All Files
in a Folder). It was designed for Word 2002, but it also works in
Word 2003. However, it doesn't work in Word 2007. When run, the
macro says there are no files in the folder even though there are
files. Can anyone tell me what changes to make so that this macro
will work? Or is there another macro somewhere or some other
process that will allow me to list the files in a folder (along with
the
file size and last modified date and time)?

Thanks in advance for your help.



  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey[_2_] Greg Maxey[_2_] is offline
external usenet poster
 
Posts: 668
Default Macro for Listing Files in a Folder

Odd. I downloaded the code as posted and ran it in both Word2003 and
Word2007 without issues.

Graham Mayor wrote:
It falsl over at
Set oFld = fso.GetFolder(pFolder)
even with Microsoft ScriptingRuntime. I have a feeling I am missing
something here


Greg Maxey wrote:
Graham,

I have no doubt that you answered the OP which I didn't read. You
can get a lot of additional information using the FileSystemObject
(requires reference to Microsoft Scripting Runtime):

Option Explicit
Dim arrFiles() As String
Dim i As Long
Sub ListFolder()
Dim TargetDoc As Document
Dim fDialog As FileDialog
Dim sPath As String
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder to list and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
sPath = fDialog.SelectedItems.Item(1) & Chr(92)
End With
arrFiles = GetFileNames(sPath)
On Error Resume Next
Set TargetDoc = Documents.Add
With TargetDoc.Range
.Font.Size = 8
.InsertAfter "File Listing of the """ & sPath & """ Folder" & vbCr &
vbCr For i = 0 To UBound(arrFiles, 2)
.InsertAfter "File name: " & arrFiles(0, i) & vbTab & "Size: " _
& arrFiles(1, i) & vbTab & "Type: " & arrFiles(2, i) _
& vbTab & "Last Modified: " & arrFiles(3, i) & vbCr & vbCr
Next i
End With
End Sub
Function GetFileNames(ByRef pFolder As String) As String()
Dim fso As New FileSystemObject
Dim oFld As Folder
Dim oFile As File
i = 0
If fso.FolderExists(pFolder) Then
Set oFld = fso.GetFolder(pFolder)
For Each oFile In oFld.Files
ReDim Preserve arrFiles(3, i)
arrFiles(0, i) = oFile.Name
arrFiles(1, i) = oFile.Size
arrFiles(2, i) = oFile.Type
arrFiles(3, i) = oFile.DateLastModified
i = i + 1
Next
GetFileNames = arrFiles
End If
End Function


Graham Mayor wrote:
Perhaps you could ask your IT support to check it out?

In the meantime

Sub ListFolder()
Dim TargetDoc As Document
Dim fDialog As FileDialog
Dim sPath As String
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder to list and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
sPath = fDialog.SelectedItems.Item(1) & Chr(92)
End With
On Error Resume Next
Set TargetDoc = Documents.Add
Selection.TypeText "File Listing of the """ & sPath & """ Folder" &
vbCr & vbCr
sName = Dir$(sPath)
Do While sName ""
Selection.TypeText sName & vbCr
sName = Dir$
Loop
End Sub

will give you a filename listing for a selected folder.


DebPgh wrote:
Graham,

Thanks for your suggestion. The two websites you referred me to
look like they have a lot of good info.

The problem is that I need this capability for my office computer.
Our company won't let us download any programs from the Internet.
Using a macro was a good way to get around this problem.

Deb

"Graham Mayor" wrote:

The routine used to list the folder content does not work in 2007
as you have found. Rather than rewrite the macro to use an
alternative routine, use the free and rather more powerful
PrintFolders utility that you can download from my web site
instead. --

Graham Mayor - Word MVP

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



DebPgh wrote:
Hi,

In the Microsoft Knowledge Base articles, there is a wonderful
macro that enables you to list all of the files in a particular
folder (Article ID:306248, WD2002: Sample Macro to List All Files
in a Folder). It was designed for Word 2002, but it also works
in Word 2003. However, it doesn't work in Word 2007. When run,
the macro says there are no files in the folder even though
there are files. Can anyone tell me what changes to make so that
this macro will work? Or is there another macro somewhere or
some other process that will allow me to list the files in a
folder (along with the
file size and last modified date and time)?

Thanks in advance for your help.


--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org

McCain/Palin '08 !!!


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing of word files in a folder dp Microsoft Word Help 1 July 30th 07 02:32 PM
Have a lot of files in Word. How can a paste a listing of these? Eightman88 Microsoft Word Help 2 April 25th 06 07:43 PM
how do I print a file listing within a folder? D. Wright Microsoft Word Help 2 January 14th 06 10:24 PM
listing files in numeric order mbenderoth Microsoft Word Help 2 December 9th 05 06:50 AM
listing of files ot spaced evenly ketch Microsoft Word Help 2 November 26th 04 08:45 PM


All times are GMT +1. The time now is 04:02 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"