Hi Guys
With the help of Kad I have managed to get my macro running so that it loops around all the files in the directory and formats it appropriately
However I have a problem with the date format. The input files have a date format of dd/mm/yy hh:mm:ss. Whereas the output file is mm/dd/yy hh:mm:ss. Also I have noticed that after (cell 1156) the format gets all mixed up for some reason and I dont really understand why. This is the code I have used and have attached the files (bout input and output). Could anyone provide some input - its driving me mad !!!
Thanks
With the help of Kad I have managed to get my macro running so that it loops around all the files in the directory and formats it appropriately
However I have a problem with the date format. The input files have a date format of dd/mm/yy hh:mm:ss. Whereas the output file is mm/dd/yy hh:mm:ss. Also I have noticed that after (cell 1156) the format gets all mixed up for some reason and I dont really understand why. This is the code I have used and have attached the files (bout input and output). Could anyone provide some input - its driving me mad !!!
Thanks
Code:
Dim Obj1 As Object
Dim Obj2 As Object
Dim UserList()
Sub RunMe()
Dim Str1 As String
Dim myPath As String
Dim i As Integer
Set Obj1 = CreateObject("excel.application")
myPath = "C:\test\" 'please note you should a "\" at the end.
Str1 = Dir(myPath & "*.xls")
Set Obj2 = CreateObject("excel.application")
Do
Obj1.Application.DisplayAlerts = False
Obj1.Workbooks.Open (myPath & Str1)
'For i = 1 To UBound(userslist)
'If Obj1.ActiveWorkbook.BuiltinDocumentProperties("Author").Value = userslist(i) Then
Call Macro1Bis 'or do whatever you want with the file
' Exit For
'End If
'Next
Obj1.ActiveWorkbook.Close
Obj1.Application.DisplayAlerts = True
Str1 = Dir()
Loop Until Str1 = ""
Set Obj1 = Nothing
Set Obj2 = Nothing
End Sub
Sub Macro1Bis()
Dim a
Dim Str1 As String
Dim Str2 As String
With Obj1.ActiveWorkbook.ActiveSheet
.Range(.Cells(2, 15), .Cells(2, 5).End(-4121).End(-4161).Offset(0, 2)).FormulaR1C1 = "=RC[-10]+RC[-9]"
.Range(.Cells(2, 16), .Cells(2, 15).End(-4121).Offset(0, 1)).FormulaR1C1 = "=RC[-7]"
a = .Range(.Cells(2, 15), .Cells(2, 16).End(-4121))
End With
Obj2.Workbooks.Add
With Obj2.ActiveWorkbook.ActiveSheet
.Range(.Cells(6, 1), .Cells(5 + UBound(a), UBound(a, 2))) = a
.Cells(5, 1) = "Time"
.Cells(5, 2) = Obj1.ActiveWorkbook.ActiveSheet.Cells(2, 3)
Select Case UCase(.Cells(5, 2))
Case "PRESSURE": Str1 = "01"
Case "FLOW": Str1 = "02"
Case "LEVEL PERCENT": Str1 = "03"
End Select
.Cells(5, 3) = Obj1.ActiveWorkbook.ActiveSheet.Cells(2, 4)
.Cells(2, 1) = "Site Name"
.Cells(2, 2) = Obj1.ActiveWorkbook.ActiveSheet.Cells(2, 1) & "_" & Obj1.ActiveWorkbook.ActiveSheet.Cells(2, 2) & "_" & Str1
Str2 = .Cells(2, 2)
Obj2.Application.DisplayAlerts = False
Obj2.ActiveWorkbook.SaveAs Filename:="C:\test\" & Str2, FileFormat:=xlCSV, CreateBackup:=False
End With
Obj2.ActiveWorkbook.Close
Obj2.Application.DisplayAlerts = True
End Sub
Comment