Getting all files of a specific type in a folder

G

Guest

Is there any way to set (and unset) the File Type name through excel VBA?

I want to list all DWG files in a directory and make hyperlinks to them, but
the problem is that different operating systems will use different file type
names e.g. some may be "Autocad 14 Drawing" where AutoCAD version 14 is
installed while others simply "DWG File" where no AutoCAD system is
installed. It would difficult to know what the file type is named as on these
other systems.

Any ideas of a way round this?

Dylan Dawson
Scotland
 
N

NickHK

No sure I follow, but does this do what you want :
Dim ACadFiles As variant

acadfiles = Application.GetOpenFilename("AutoCad File
(*.dwg;*.dwf),*.dwg;*.dwf", , "Select the AutoCad Files", , True)
if isarray(acadfile) then
'...etc

Change the file type filter to those used by AutoCad
Note this does not open the files; onlt returns an array of filename for you
do what you wish.

Or you just want the user to choose a folder and then you process the files
in that folder yourself, look at the SHBrowseForFolder API.
http://vbnet.mvps.org/code/browse/browsefolders.htm

NickHK
 
G

Guest

Nick,

I should have included code as info, the project contains a Loopfolders
Function which starts with:

Function LoopFolders(startPath As String, _
Optional filetype As String = "AutoCAD 14 Drawing", _
Optional subfolders As Boolean = True)

' Create named Ranges, for the appropriate columns in Row 8 of Worksheet
etc..

[SNIP]
And the Worksheet contains a command button with the line:

LoopFolders Range("root").Value, "Microsoft Excel Worksheet"

The worksheet is an index which automatically creates hyperlinks to the
files and I have used it for PDF files etc. where the filetype rarely varies.
But AutoCAD type files are a bugbear. Hope you can help.

Regards
Dylan
 
N

NickHK

I don't see how/where you are using the filetype "AutoCAD 14 Drawing".
What are you calling with this string ?

NickHK
 
G

Guest

Nick,

I did it again, sorry Monday mornings.

the second part should be:
[SNIP]
And the Worksheet contains a command button with the line:

LoopFolders Range("root").Value, "AutoCAD 14 Drawing"

' Not "Microsoft Excel Worksheet" as previously denoted


NickHK said:
I don't see how/where you are using the filetype "AutoCAD 14 Drawing".
What are you calling with this string ?

NickHK

DDawson said:
Nick,

I should have included code as info, the project contains a Loopfolders
Function which starts with:

Function LoopFolders(startPath As String, _
Optional filetype As String = "AutoCAD 14 Drawing", _
Optional subfolders As Boolean = True)

' Create named Ranges, for the appropriate columns in Row 8 of Worksheet
etc..

[SNIP]
And the Worksheet contains a command button with the line:

LoopFolders Range("root").Value, "Microsoft Excel Worksheet"

The worksheet is an index which automatically creates hyperlinks to the
files and I have used it for PDF files etc. where the filetype rarely varies.
But AutoCAD type files are a bugbear. Hope you can help.

Regards
Dylan
 
J

Jim Cone

The free "List Files" Excel add-in will list all files in a folder/subfolders
meeting a specified requirement... *.dwg for instance.
Hyperlinks are included.
Download from ... http://www.realezsites.com/bus/primitivesoftware
No registration required.
--
Jim Cone
San Francisco, USA


"DDawson" <[email protected]>
wrote in message
Is there any way to set (and unset) the File Type name through excel VBA?

I want to list all DWG files in a directory and make hyperlinks to them, but
the problem is that different operating systems will use different file type
names e.g. some may be "Autocad 14 Drawing" where AutoCAD version 14 is
installed while others simply "DWG File" where no AutoCAD system is
installed. It would difficult to know what the file type is named as on these
other systems.
Any ideas of a way round this?
Dylan Dawson
Scotland
 
N

NickHK

I can't help you yet, as I do not know why you need to use file types like
"AutoCAD 14 Drawing". I would have thought using the file extension (*.dwg)
would be sufficient. If so, see Jim's post.
If not, explain why you need to work such strings.

NickHK

DDawson said:
Nick,

I did it again, sorry Monday mornings.

the second part should be:
[SNIP]
And the Worksheet contains a command button with the line:

LoopFolders Range("root").Value, "AutoCAD 14 Drawing"

' Not "Microsoft Excel Worksheet" as previously denoted


NickHK said:
I don't see how/where you are using the filetype "AutoCAD 14 Drawing".
What are you calling with this string ?

NickHK

DDawson said:
Nick,

I should have included code as info, the project contains a Loopfolders
Function which starts with:

Function LoopFolders(startPath As String, _
Optional filetype As String = "AutoCAD 14 Drawing", _
Optional subfolders As Boolean = True)

' Create named Ranges, for the appropriate columns in Row 8 of Worksheet
etc..

[SNIP]
And the Worksheet contains a command button with the line:

LoopFolders Range("root").Value, "Microsoft Excel Worksheet"

The worksheet is an index which automatically creates hyperlinks to the
files and I have used it for PDF files etc. where the filetype rarely varies.
But AutoCAD type files are a bugbear. Hope you can help.

Regards
Dylan
 
N

NickHK

If you need to work with File types like this, may Ivan's code can help:
http://www.xcelfiles.com/ShellFileType.html

NickHK

DDawson said:
Nick,

I did it again, sorry Monday mornings.

the second part should be:
[SNIP]
And the Worksheet contains a command button with the line:

LoopFolders Range("root").Value, "AutoCAD 14 Drawing"

' Not "Microsoft Excel Worksheet" as previously denoted


NickHK said:
I don't see how/where you are using the filetype "AutoCAD 14 Drawing".
What are you calling with this string ?

NickHK

DDawson said:
Nick,

I should have included code as info, the project contains a Loopfolders
Function which starts with:

Function LoopFolders(startPath As String, _
Optional filetype As String = "AutoCAD 14 Drawing", _
Optional subfolders As Boolean = True)

' Create named Ranges, for the appropriate columns in Row 8 of Worksheet
etc..

[SNIP]
And the Worksheet contains a command button with the line:

LoopFolders Range("root").Value, "Microsoft Excel Worksheet"

The worksheet is an index which automatically creates hyperlinks to the
files and I have used it for PDF files etc. where the filetype rarely varies.
But AutoCAD type files are a bugbear. Hope you can help.

Regards
Dylan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top