Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Naming a file with the same name as the folder

Hi,

Im extracting some text files in to excel using Application.File Search
method

The folder Im looking inside is "C:\Documents and
Settings\abc\Desktop\Automate\Dev\From Client\Raw Data"
The Raw data has different subfolders called "week 1", "week 2" etc. My
target text files are within each of these "week 1", "week 2" etc folders

When I get the name of the text file using -- .FoundFiles(i) - I want to
rename the text file with name of the subfolder in which it is found.
For example if I find a file in "Week 1" I want to name it as week 1.xls and
store it within the folder "C:\Documents and Settings\abc\Desktop\xlfomat".

I have given my present code below. Please guide me on how to Manipulate the
value of "newpathfilename" so that sub folder name could be extracted from
"oldpathfilename" and subsequently the new XLS file is stored in the folder
"C:\Documents and Settings\abc\Desktop\xlfomat" with name being week1. xls
or so.



Sub RenamingLSTasXLS(oldpathfilename as string)

dim

Workbooks.OpenText Filename:= _
oldpathfilename, Origin:=437, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:= _
newpathfilename, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,_
CreateBackup:=False

ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub



Sub OpenLSTfilesInLocation()

Application.ScreenUpdating = False
Dim i As Integer
With Application.FileSearch
.NewSearch
.LookIn = "C:\Documents and Settings\abc\Desktop\Automate\Dev\From
Client\Raw Data"
.SearchSubFolders = True
Filename = "*.lst"
.Execute
For i = 1 To .FoundFiles.Count
Call RenamingLSTasXLS (.FoundFiles(i))
Next i
End With
Application.ScreenUpdating = True

End Sub



--
Regards,
Hari
India


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Naming a file with the same name as the folder

Sub RenamingLSTasXLS(oldpathfilename as string)


Workbooks.OpenText Filename:= _
oldpathfilename, Origin:=437, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True

varr = Split(oldpathfilename,"\")
ub = Ubound(varr)
wk = varr(ub-1)
nwPathfilename = "C:\Documents and Settings\abc\Desktop\xlfomat\" &
wk & ".xls"
Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:= _
newpathfilename, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,_
CreateBackup:=False

ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub

--
Regards,
Tom Ogilvy


"Hari" wrote in message
...
Hi,

Im extracting some text files in to excel using Application.File Search
method

The folder Im looking inside is "C:\Documents and
Settings\abc\Desktop\Automate\Dev\From Client\Raw Data"
The Raw data has different subfolders called "week 1", "week 2" etc. My
target text files are within each of these "week 1", "week 2" etc folders

When I get the name of the text file using -- .FoundFiles(i) - I want to
rename the text file with name of the subfolder in which it is found.
For example if I find a file in "Week 1" I want to name it as week 1.xls

and
store it within the folder "C:\Documents and

Settings\abc\Desktop\xlfomat".

I have given my present code below. Please guide me on how to Manipulate

the
value of "newpathfilename" so that sub folder name could be extracted from
"oldpathfilename" and subsequently the new XLS file is stored in the

folder
"C:\Documents and Settings\abc\Desktop\xlfomat" with name being week1. xls
or so.



Sub RenamingLSTasXLS(oldpathfilename as string)

dim

Workbooks.OpenText Filename:= _
oldpathfilename, Origin:=437, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:= _
newpathfilename, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,_
CreateBackup:=False

ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub



Sub OpenLSTfilesInLocation()

Application.ScreenUpdating = False
Dim i As Integer
With Application.FileSearch
.NewSearch
.LookIn = "C:\Documents and Settings\abc\Desktop\Automate\Dev\From
Client\Raw Data"
.SearchSubFolders = True
Filename = "*.lst"
.Execute
For i = 1 To .FoundFiles.Count
Call RenamingLSTasXLS (.FoundFiles(i))
Next i
End With
Application.ScreenUpdating = True

End Sub



--
Regards,
Hari
India




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
Auto file naming Jacquesvv Excel Discussion (Misc queries) 1 June 23rd 09 02:57 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
Create Folder and Text File in folder Todd Huttentsine Excel Programming 2 April 29th 04 03:41 PM
MS Excel "path" and XP/NTFS folder naming weavtennis Excel Programming 1 December 9th 03 01:51 PM
Naming File from a Cell RisingStar Excel Programming 1 August 10th 03 04:46 AM


All times are GMT +1. The time now is 10:55 PM.

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

About Us

"It's about Microsoft Excel"