Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

need help adjust macro a little

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
trend5 - 24 Mar 2005 18:34 GMT
need help to customize microsoft code a little:
code sample:

http://support.microsoft.com/?kbid=306248
 
(this macro just create a list of all files in a specified folder).

I want just adjust this macro a little:

1. set file search for .mp3 and .M3U file types only.

2. no 'File Date/Time' listing required, only file name and size.

3.  I need list only file name - without full path specified, i.e.
'Rainbow.mp3'
(Currently macro list full path - C:\Documents and Settings\User\My
Documents\mp3utilities\Rainbow.mp3)

4. I want that the list was numbered( 01, 02...)

5. show file size in Megabytes (i.e. 4,5Mb), not in bytes

thanks.
Dave Lett - 24 Mar 2005 19:24 GMT
Hi trend,

If you don't need the file size, then you can use the information from the
article "How to read the filenames of all the files in a directory into an
array" at http://word.mvps.org/faqs/macrosvba/ReadFilesIntoArray.htm

You would end up with something like the following:

Dim sPath As String
Dim MyFile As String
Dim Counter As Long

sPath = "c:\test\"
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)

'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$(sPath & "*.mp3")
Do While MyFile <> ""
   DirectoryListArray(Counter) = MyFile
   MyFile = Dir$
   Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by using Redim
Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
For Counter = 0 To UBound(DirectoryListArray)
   sFileInfo = sFileInfo & Counter + 1 & vbTab
   sFileInfo = sFileInfo & DirectoryListArray(Counter) & vbTab
   sFileInfo = sFileInfo & FileLen("c:\test\" &
DirectoryListArray(Counter)) / 1000 & vbCrLf
Next Counter
MsgBox sFileInfo

This shows the size of the file in kilobytes (you have to help yourself some
to get it to megabytes). You will need to change the line
MyFile = Dir$(sPath & "*.mp3")
to
MyFile = Dir$(sPath & "*.M3U")
to account for the other file type.

HTH,
Dave

> need help to customize microsoft code a little:
> code sample:
[quoted text clipped - 19 lines]
>
> thanks.
TANDEX - 24 Mar 2005 20:00 GMT
> Hi trend,
>
[quoted text clipped - 66 lines]
>>
>> thanks.
---------------------------------

Dave,

I need list 'File name' and 'File size'(in Mb).
Also,  how to implement way to retrieve the folder name that the user
selected by calling the standard 'Browse folder dialog'?  i.e. implement
integrated browsing capability, to select required folder via browsing, more
easily. Currently code use just input box where exact patch to folder should
be entered manually.
Dave Lett - 24 Mar 2005 20:46 GMT
Hi,

You can call the Copy File dialog box to allow the user to navigate to a
folder. As for changing from kilobytes to megabytes, have a search on the
Internet or something and do a LITTLE to help yourself.

Dim sPath As String
Dim MyFile As String
Dim Counter As Long
With Dialogs(wdDialogCopyFile)
   .Display
   sPath = .Directory
End With
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)

'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$(sPath & "*.doc")
Do While MyFile <> ""
   DirectoryListArray(Counter) = MyFile
   MyFile = Dir$
   Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by using Redim
Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
For Counter = 0 To UBound(DirectoryListArray)
   sFileInfo = sFileInfo & Counter + 1 & vbTab
   sFileInfo = sFileInfo & DirectoryListArray(Counter) & vbTab
   sFileInfo = sFileInfo & FileLen("c:\test\" &
DirectoryListArray(Counter)) / 1000 & vbCrLf
Next Counter
MsgBox sFileInfo

> > Hi trend,
> >
[quoted text clipped - 76 lines]
> easily. Currently code use just input box where exact patch to folder should
> be entered manually.
TANDEX - 24 Mar 2005 21:08 GMT
> Hi,
>
[quoted text clipped - 116 lines]
> should
>> be entered manually.

----------------
Hi,

I tried this code and it not work.
Dave Lett - 25 Mar 2005 14:21 GMT
Maybe you could be a little more specific that it not work?

Dave

> > Hi,
> >
[quoted text clipped - 121 lines]
>
> I tried this code and it not work.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.