Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default File Lister- (Code help) Pull File Name without Extension into Col

I'm trying to pull in *.dwg files into a Column
So I'll have a list of all my drawing files. I'm wondering if I can change
the code so that it only pulls in the file name without the extension. Then
that would save me some extra code and making more macros to remove the file
extension from column with an additional macro.

Sub Load_Files()
'dimension variables
Dim objFSO As FileSystemObject, objFolder As Folder
Dim objFile As File, strSourceFolder As String, x As Long, i As Long
Dim wbNew As Workbook, wsNew As Worksheet

ToggleStuff False 'turn of screenupdating

Set objFSO = New FileSystemObject 'set a new object in memory
strSourceFolder = BrowseForFolder 'call up the browse for folder routine
If strSourceFolder = "" Then Exit Sub

'create a new workbook -Deleted this function-BDC -Workbooks.Add-

Set wbNew = ActiveWorkbook
Set wsNew = wbNew.Sheets(2) 'set the worksheet which is worksheet tab 2
wsNew.Activate
'format a header
With wsNew.Range("A1:F1")
.Value = Array("File", "Size", "Modified Date", "Last Accessed",
"Created Date", "Full Path", "Size")
.Interior.ColorIndex = 34
.Font.Bold = True
.Font.Size = 12
End With

With Application.FileSearch
.LookIn = strSourceFolder 'look in the folder browsed to
.FileType = msoFileTypeAllFiles 'get all files
.SearchSubFolders = False 'don't search sub directories
.Filename = "*.dwg" 'This selects what kind of File Type -We're
using AutoCad Here
.Execute 'run the search

For x = 1 To .FoundFiles.Count 'for each file found, by the count
(or index)
i = x 'make the variable i = x
If x 60000 Then 'if there happens to be more than multipls of
60,000 files, then add a new sheet
i = x - 60000 'set i to the right number for row placement
below
Set wsNew = wbNew.Sheets.Add(After:=Sheets(wsNew.Index))
With wsNew.Range("A1:F1")
.Value = Array("File", "Parent Folder", "Full Path",
"Modified Date", _
"Last Accessed", "Size")
.Interior.ColorIndex = 7
.Font.Bold = True
.Font.Size = 12
End With

End If
On Error GoTo Skip 'in the event of a permissions error

Set objFile = objFSO.GetFile(.FoundFiles(x)) 'set the object to
get it's properties
With wsNew.Cells(1, 1) 'populate the next row with the variable
data
.Offset(i, 0) = objFile.Name
.Offset(i, 1) = FORMAT(objFile.Size, "0,000") & " KB"
.Offset(i, 2) = objFile.DateLastModified
.Offset(i, 3) = objFile.DateLastAccessed
.Offset(i, 4) = objFile.DateCreated
.Offset(i, 5) = objFile.Path

End With
' Next objFile
Skip:
'this is in case a Permission denied error comes up or an
unforeseen error
'Do nothing, just go to next file
Next x
wsNew.Columns("A:F").AutoFit

End With

'clear the variables
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
Set wsNew = Nothing
Set wbNew = Nothing

ToggleStuff True 'turn events back on
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default File Lister- (Code help) Pull File Name without Extension intoCol

On Jul 16, 10:01*am, Benjamin
wrote:
I'm trying *to pull in *.dwg files into a Column
So I'll have a list of all my drawing files. I'm wondering if I can change
the code so that it only pulls in the file name without the extension. Then
that would save me some extra code and making more macros to remove the file
extension from column with an additional macro.

Sub Load_Files()
* * *'dimension variables
* * Dim objFSO As FileSystemObject, objFolder As Folder
* * Dim objFile As File, strSourceFolder As String, x As Long, i As Long
* * Dim wbNew As Workbook, wsNew As Worksheet

* * ToggleStuff False 'turn of screenupdating

* * Set objFSO = New FileSystemObject 'set a new object in memory
* * strSourceFolder = BrowseForFolder 'call up the browse for folder routine
* * If strSourceFolder = "" Then Exit Sub

* * 'create a new workbook -Deleted this function-BDC * -Workbooks.Add-

* * Set wbNew = ActiveWorkbook
* * Set wsNew = wbNew.Sheets(2) 'set the worksheet which is worksheet tab 2
* * wsNew.Activate
* * *'format a header
* * With wsNew.Range("A1:F1")
* * * * .Value = Array("File", "Size", "Modified Date", "Last Accessed",
"Created Date", "Full Path", "Size")
* * * * .Interior.ColorIndex = 34
* * * * .Font.Bold = True
* * * * .Font.Size = 12
* * End With

* * With Application.FileSearch
* * * * .LookIn = strSourceFolder 'look in the folder browsed to
* * * * .FileType = msoFileTypeAllFiles 'get all files
* * * * .SearchSubFolders = False 'don't search sub directories
* * * * .Filename = "*.dwg" 'This selects what kind of File Type -We're
using AutoCad Here
* * * * .Execute 'run the search

* * * * For x = 1 To .FoundFiles.Count 'for each file found, by the count
(or index)
* * * * * * i = x 'make the variable i = x
* * * * * * If x 60000 Then 'if there happens to be more than multipls of
60,000 files, then add a new sheet
* * * * * * * * i = x - 60000 'set i to the right number for row placement
below
* * * * * * * * Set wsNew = wbNew.Sheets.Add(After:=Sheets(wsNew.Index))
* * * * * * * * With wsNew.Range("A1:F1")
* * * * * * * * * * .Value = Array("File", "Parent Folder", "Full Path",
"Modified Date", _
* * * * * * * * * * "Last Accessed", "Size")
* * * * * * * * * * .Interior.ColorIndex = 7
* * * * * * * * * * .Font.Bold = True
* * * * * * * * * * .Font.Size = 12
* * * * * * * * End With

* * * * * * End If
* * * * * * On Error GoTo Skip 'in the event of a permissions error

* * * * * * Set objFile = objFSO.GetFile(.FoundFiles(x)) 'set the object to
get it's properties
* * * * * * With wsNew.Cells(1, 1) 'populate the next row with the variable
data
* * * * * * * * .Offset(i, 0) = objFile.Name
* * * * * * * * .Offset(i, 1) = FORMAT(objFile.Size, "0,000") & " KB"
* * * * * * * * .Offset(i, 2) = objFile.DateLastModified
* * * * * * * * .Offset(i, 3) = objFile.DateLastAccessed
* * * * * * * * .Offset(i, 4) = objFile.DateCreated
* * * * * * * * .Offset(i, 5) = objFile.Path

* * * * * * End With
* * * * * * *' Next objFile
Skip:
* * * * * * *'this is in case a Permission denied error comes up or an
unforeseen error
* * * * * * *'Do nothing, just go to next file
* * * * Next x
* * * * wsNew.Columns("A:F").AutoFit

* * End With

* * *'clear the variables
* * Set objFolder = Nothing
* * Set objFile = Nothing
* * Set objFSO = Nothing
* * Set wsNew = Nothing
* * Set wbNew = Nothing

* * ToggleStuff True 'turn events back on


Benjamin,

Use the Object Browser (View | Object Browser) to search for
"FileSystemObject". You'll notice that the class has a number of
methods associated with it. You are likely looking for GetBaseName.
(You can also search "GetBaseName" in VBE Help. The help file states
the following: "Returns a string containing the base name of the last
component, less any file extension, in a path." If this isn't what
you are looking for, then click the "See Also" link within the
GetBaseName help file to search other related methods).

Dim strBaseName
strBaseName = objFSO.GetBaseName(objFile.Path)

Best,

Matthew Herbert
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default File Lister- (Code help) Pull File Name without Extension into Col

Aircode:

from
.Offset(i, 0) = objFile.Name
to
.Offset(i, 0) = left(objFile.Name,len(objFile.Name)-4)

HTH
Keith

"Benjamin" wrote:

I'm trying to pull in *.dwg files into a Column
So I'll have a list of all my drawing files. I'm wondering if I can change
the code so that it only pulls in the file name without the extension. Then
that would save me some extra code and making more macros to remove the file
extension from column with an additional macro.

Sub Load_Files()
'dimension variables
Dim objFSO As FileSystemObject, objFolder As Folder
Dim objFile As File, strSourceFolder As String, x As Long, i As Long
Dim wbNew As Workbook, wsNew As Worksheet

ToggleStuff False 'turn of screenupdating

Set objFSO = New FileSystemObject 'set a new object in memory
strSourceFolder = BrowseForFolder 'call up the browse for folder routine
If strSourceFolder = "" Then Exit Sub

'create a new workbook -Deleted this function-BDC -Workbooks.Add-

Set wbNew = ActiveWorkbook
Set wsNew = wbNew.Sheets(2) 'set the worksheet which is worksheet tab 2
wsNew.Activate
'format a header
With wsNew.Range("A1:F1")
.Value = Array("File", "Size", "Modified Date", "Last Accessed",
"Created Date", "Full Path", "Size")
.Interior.ColorIndex = 34
.Font.Bold = True
.Font.Size = 12
End With

With Application.FileSearch
.LookIn = strSourceFolder 'look in the folder browsed to
.FileType = msoFileTypeAllFiles 'get all files
.SearchSubFolders = False 'don't search sub directories
.Filename = "*.dwg" 'This selects what kind of File Type -We're
using AutoCad Here
.Execute 'run the search

For x = 1 To .FoundFiles.Count 'for each file found, by the count
(or index)
i = x 'make the variable i = x
If x 60000 Then 'if there happens to be more than multipls of
60,000 files, then add a new sheet
i = x - 60000 'set i to the right number for row placement
below
Set wsNew = wbNew.Sheets.Add(After:=Sheets(wsNew.Index))
With wsNew.Range("A1:F1")
.Value = Array("File", "Parent Folder", "Full Path",
"Modified Date", _
"Last Accessed", "Size")
.Interior.ColorIndex = 7
.Font.Bold = True
.Font.Size = 12
End With

End If
On Error GoTo Skip 'in the event of a permissions error

Set objFile = objFSO.GetFile(.FoundFiles(x)) 'set the object to
get it's properties
With wsNew.Cells(1, 1) 'populate the next row with the variable
data
.Offset(i, 0) = objFile.Name
.Offset(i, 1) = FORMAT(objFile.Size, "0,000") & " KB"
.Offset(i, 2) = objFile.DateLastModified
.Offset(i, 3) = objFile.DateLastAccessed
.Offset(i, 4) = objFile.DateCreated
.Offset(i, 5) = objFile.Path

End With
' Next objFile
Skip:
'this is in case a Permission denied error comes up or an
unforeseen error
'Do nothing, just go to next file
Next x
wsNew.Columns("A:F").AutoFit

End With

'clear the variables
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
Set wsNew = Nothing
Set wbNew = Nothing

ToggleStuff True 'turn events back on

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine Excel file version with no file extension. tjlumpkin Excel Discussion (Misc queries) 2 July 23rd 09 06:59 AM
Retrieving Excel File extension based on XL File Format Enumeratio Sasikumar Kannappan Excel Programming 2 June 24th 09 03:59 PM
file format or file extension is not valid...error message Ballun Excel Discussion (Misc queries) 0 May 7th 09 09:06 PM
Additional file with no extension created during File Save As proc Peter Rooney Excel Discussion (Misc queries) 2 August 11th 05 02:48 PM
I need to download an exel spreadsheet file. (file extension :xls) buckrogers Excel Discussion (Misc queries) 2 December 8th 04 11:08 PM


All times are GMT +1. The time now is 08:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"