Sub
CSVXLS_variabel()
Dim
wb
As
Workbook
Dim
strFile
As
String
, strDir
As
String
, strTXT_File
As
String
Dim
bolTab
As
Boolean
, bolSemicolon
As
Boolean
, bolComma
As
Boolean
, _
bolSpace
As
Boolean
, bolOther
As
Boolean
, strOther
As
String
, strSep
As
String
strSep = InputBox(
"Bitte Trennzeichen eingeben (Für Tabulator: vbTab)"
, _
"Trennzeichen für CSV-Import"
,
Default
:=
"vbTab"
)
Select
Case
strSep
Case
""
Exit
Sub
Case
"vbTab"
: bolTab =
True
Case
";"
: bolSemicolon =
True
Case
","
: bolComma =
True
Case
" "
: bolSpace =
True
Case
Else
bolOther =
True
strOther = Left(strSep, 1)
End
Select
strDir = "C:\temp\MD-Rechnung\"
strFile = Dir(strDir &
"*.csv"
)
Do
While
strFile <>
""
strTXT_File = strDir & strFile
strTXT_File = Replace(strTXT_File,
".csv"
,
".txt"
)
VBA.FileCopy Source:=strDir & strFile, Destination:=strTXT_File
Workbooks.OpenText Filename:=strTXT_File, Tab:=bolTab, _
semicolon:=bolSemicolon, comma:=bolComma, Space:=bolSpace, _
other:=bolOther, otherChar:=strOther, Local:=
True
Set
wb = ActiveWorkbook
wb.SaveAs Replace(wb.FullName,
".txt"
,
".xlsx"
), 51
wb.Close
True
Set
wb =
Nothing
Kill strTXT_File
strFile = Dir
Loop
End
Sub
Sub
OeffnenDialog_mit_Pfadvorgabe()
Dim
wb
As
Workbook
Dim
lngZ
As
Long
Dim
strFileName
Dim
strFilter
As
String
strFilter =
"Excel-Dateien(*.xl*), *.xl*"
ChDrive
"C"
ChDir
"C:\temp\MD-Rechnung"
strFileName = Application.GetOpenFilename(strFilter)
If
strFileName =
False
Then
Exit
Sub
Set
wb = Workbooks.Open(strFileName)
MsgBox
"Die Datei '"
& wb.Name &
"' wurde geöffnet."
, vbInformation,
"Hinweis"
End
Sub