Hi
My first post in this glorious forum so please be gentle
I'm trying to get Excel to copy data from a text file and then arranging it for me, and it works like a charm. Except for 2 things!
The characters ┼ and ─ seems impossible to replace
I have figured out that they should be ANSI 197 and 196 but I still won't succeed!
Please guide me
My code:
Sub Skapa_ANLU()
Dim ret
ret = Application.GetOpenFilename()
Range("A1").Select
If ret <> False Then
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & ret, Destination:=Range("$A$1"))
' .Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
' .TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End If
Columns("M:S").Select
Selection.Delete Shift:=xlToLeft
Range("A:C").Select
Selection.Replace "õ", "ä", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="Õ", Replacement:="å", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="Í", Replacement:="Ö", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace Chr(197), "Å", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="÷", Replacement:="ö", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace Chr(196), Replacement:="Ä", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Columns("E:M").Select
Selection.NumberFormat = "#,##0"
Range("A1").Select
End Sub
My first post in this glorious forum so please be gentle
I'm trying to get Excel to copy data from a text file and then arranging it for me, and it works like a charm. Except for 2 things!
The characters ┼ and ─ seems impossible to replace
I have figured out that they should be ANSI 197 and 196 but I still won't succeed!
Please guide me
My code:
Sub Skapa_ANLU()
Dim ret
ret = Application.GetOpenFilename()
Range("A1").Select
If ret <> False Then
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & ret, Destination:=Range("$A$1"))
' .Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
' .TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End If
Columns("M:S").Select
Selection.Delete Shift:=xlToLeft
Range("A:C").Select
Selection.Replace "õ", "ä", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="Õ", Replacement:="å", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="Í", Replacement:="Ö", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace Chr(197), "Å", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="÷", Replacement:="ö", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace Chr(196), Replacement:="Ä", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Columns("E:M").Select
Selection.NumberFormat = "#,##0"
Range("A1").Select
End Sub