View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Roger Govier[_3_] Roger Govier[_3_] is offline
external usenet poster
 
Posts: 2,480
Default DIR fn when filename has non-ANSI characters

Hi Simon

Could you not just create a folder called C:\Simon and drag all of the files
to that location?

--
Regards
Roger Govier

"simonc" wrote in message
...
Roger

This looks more promising. Unfortunately some of these files are in
folders
which have Russian characters in the name and when I paste the folder name
into strPath it again substitutes question marks for each non-ANSI
character.
Is there a way round this?

Could you also tell me how to set the macro so it will recognise folders
as
well as files when it is going through the For...Next loop?

Thanks

Simon

"Roger Govier" wrote:

Hi Simon

Why do you want to do it with DIR?
Could you not use the File Scripting Object to do it directly through
VBA?

Here is some code posted by Jim Cone which should do what you want.

Sub ListAllFilesInFolder()
'Jim Cone - Portland Oregon - USA
Dim strPath As String
Dim oFSO As Object
Dim oFile As Object
Dim oFolder As Object
Dim N As Long

strPath = "C:\Program Files\Microsoft Office\Office11"

N = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(strPath)
Cells(N, 1).Value = oFolder.Path
N = N + 1
For Each oFile In oFolder.Files
Cells(N, 2).Value = oFile.Name
N = N + 1
Next 'oFile
Set oFSO = Nothing
Set oFile = Nothing
Set oFolder = Nothing
End Sub



--
Regards
Roger Govier