Sub Auto_Open()
'
' import2 Makro
'
Dim DecMinFromString As Double
Dim s As String
Dim Hours As Long, Mins As Long, Secs As Long
Dim nHours As Double, nMins As Double, nSecs As Double, i As Byte, p As Long
'
ChDir "\\czlibefp01\users\michal.bambusz\dočasné" 'definice složky
Cells.Select 'smazani predchiziho obsahu v celem listu
Selection.Delete Shift:=xlUp 'smazani predchiziho obsahu v celem listu
soubor = Application.GetOpenFilename("zdrojova data (*.csv),*.csv")
Application.ScreenUpdating = False 'zakaz překreslování obrazovky
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;\\czlibefp01\users\michal.bambusz\dočasné\november.csv", Destination:= _
Range("$A$1"))
.Name = "november"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveWindow.SmallScroll Down:=-12
Range("A1").Select
Columns("O:O").Select 'změna formátu čísla
Selection.Replace What:=".", Replacement:=",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
p = Range("A1").CurrentRegion.Rows.Count 'vrati pocet radku do p
Range("A1").Select
For i = 2 To p
s = Cells(i, 15).Value
If s = "" Then 'pokud je hodnota O = 0 pak preskoc dal
GoTo preskoc
End If
s = Replace(s, " ", "") 'mezery pryč
Hours = InStr(s, "h") 'nefunguje korektně vynulování, proč?
If Hours > 0 Then
nHours = Left(s, Hours - 1)
s = Right(s, Len(s) - Hours)
Else 'nutno dodat else, pak funguje OK
nHours = 0
End If
Mins = InStr(s, "m")
If Mins > 0 Then
nMins = Left(s, Mins - 1)
s = Right(s, Len(s) - Mins)
End If
Secs = InStr(s, "s")
If Secs > 0 Then
nSecs = Left(s, Secs - 1)
s = Right(s, Len(s) - Secs)
Else
nSecs = 0
End If
DecMinFromString = 60# * nHours + nMins + nSecs / 60#
Cells(i, 16) = DecMinFromString 'zapis hodnoty do bunky
' ActiveCell.Offset(1, 0).Select 'vybereme bunku ktera je o 1 radek nize, stejny sloupecek
preskoc:
Next i
' Range("q1").Select
End Sub