navash
Mechanical
- Feb 27, 2007
- 9
Hi,
I want to open all the ".lis" files in a particular folder in Excel, format them and save them as "XML Spreadsheets" in the same folder with the same File Name.
e.g "FileName.lis" is opened in Excel, formatted and saved in the same directory with new name as "Filename.xml"
.lis files are ANSYS output files similar to .dat files
I have written the following macro but it doesn't seem to work right. Please guide me write this. I also attach a sample .lis file just in case you might need to check.
Code:
Sub Macro2()
'
Dim strFile As String
Dim strPath As String
With Application
.EnableEvents = False
'.DisplayAlerts = False
.ScreenUpdating = False
End With
strPath = "C:\Documents and Settings\Jhintak\Desktop\Macro Test\"
strFile = Dir(strPath & "*.lis")
Do While strFile <> ""
Workbooks.Open (strPath & strFile), Origin:= _
437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), _
Array(8, 1), Array(21, 1), Array(33, 1), Array(46, 1), Array(55, 1), Array(68, 1)), _
TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:=strPath & strFile, FileFormat:= _
xlXMLSpreadsheet, ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close True
strFile = Dir
Loop
End Sub
I want to open all the ".lis" files in a particular folder in Excel, format them and save them as "XML Spreadsheets" in the same folder with the same File Name.
e.g "FileName.lis" is opened in Excel, formatted and saved in the same directory with new name as "Filename.xml"
.lis files are ANSYS output files similar to .dat files
I have written the following macro but it doesn't seem to work right. Please guide me write this. I also attach a sample .lis file just in case you might need to check.
Code:
Sub Macro2()
'
Dim strFile As String
Dim strPath As String
With Application
.EnableEvents = False
'.DisplayAlerts = False
.ScreenUpdating = False
End With
strPath = "C:\Documents and Settings\Jhintak\Desktop\Macro Test\"
strFile = Dir(strPath & "*.lis")
Do While strFile <> ""
Workbooks.Open (strPath & strFile), Origin:= _
437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), _
Array(8, 1), Array(21, 1), Array(33, 1), Array(46, 1), Array(55, 1), Array(68, 1)), _
TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:=strPath & strFile, FileFormat:= _
xlXMLSpreadsheet, ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close True
strFile = Dir
Loop
End Sub