Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Reba Wright   on Sep 04 In MS Office Category.

  
Question Answered By: Boyce Fischer   on Sep 04

These are both very straight-forward questions.
Your question about a "go-to" source is harder!

For the first task:
Your first step is to record a macro in which you
open one of the files, change the formatting,
then save it as an xls file.

I'm using excel  2007, so the syntax may be different.

I came up with:

Sub Refile()
Dim Folder, File, Files, f, fso
Dim NewFileName
Set fso = CreateObject("Scripting.FileSystemObject")
Folder = "C:\temp"
Set f = fso.GetFolder(Folder)
Set files  = f.Files
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each file  In Files
If (UCase(fso.getextensionname(File.Path)) = "CSV") Then
NewFileName = Replace(File.Name, ".csv", ".xls")
Workbooks.Open Filename:=File.Path
Windows("standard.xls").Activate
Cells.Select
Selection.Copy
Windows(File.Name).Activate
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("B2").Select
ActiveWindow.FreezePanes = True
Application.CutCopyMode = False
ActiveWorkbook.SaveAs Filename:=Folder & "\" & NewFileName,
FileFormat:= _
xlExcel8, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWorkbook.Close
End If
Next File
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Now, if I remember right, Excel 2003 uses File.FullName instead of File.Name for
the name with the path.


Now, question 2:

There's lots of approaches.
One way would be to read through the lines and write them out as separate txt
files, then use the above macro to open them and file them.

Or, you could read through and copy the line to a separate worksheet in the same
workbook.
Then, have the macro move each sheet to a new book and save it.
Each approach has it's limitations.
But the first step is to decide what you want to call the files or sheets?

Share: 

 
 
Didn't find what you were looking for? Find more on Creating files based on names in a column Or get search suggestion and latest updates.


Tagged: