so langsam komme ich dahinter, wie das mit der Programmierung in OO läuft.
Habe mir für Calc das Makro unten gestrickt. Das schreibt mir alle Dateinamen aus einem festgelegten Verzeichnis in ein Grid in Spalte A.
Die Files, die ich auslese, sind immer genau so aufgebaut:
20010801 xyzAB.pdf
20101229 qwertBA.pdf
20110313 zubABqwer.pdf
20120131 BAzzs.pdf
etc.
Also vorne immer das Datum rückwärts und dann ein Text dazu. Der Text enthält immer entweder den Code "AB" irgendwo oder "BA".
Kann mir jemand helfen den String NextFile aufzutrennen: Ich brauche eine Variable FileDate (die dann als Datum formatiert) z. B. "1.8.2001" enthält. Das schreibe ich dann in Spalte B. Und ich brauche in einer Variablen FileCode "AB" oder "BA" (je nachdem was er im Filenamen findet) - das schreibe ich dann in Spalte C.
Danke,
Reginald
Code: Alles auswählen
Sub Read_all_files_and_write_them
Dim NextFile As String
Dim AllFiles As String
Dim SourcePath As String
Dim DestinationPath As String
Dim SourceFile As String
Dim oForm as Object
mydoc = ThisComponent
mySheet = myDoc.sheets(0)
StartColumn = 0 'This can be adjusted. Consider the offset (A = 0 ...)
StartRow = 1 'This can be adjusted, too
NextRow = StartRow
SourcePath="C:\" 'Don't forget the \ at the end!
SourceFile=SourcePath
NextFile = Dir(SourcePath, 0)
MsgBox NextFile
While NextFile <> ""
'MsgBox NextFile
mycell = mysheet.getCellByPosition(StartColumn,NextRow) ' focus auf 0,0 setzen
mycell.string = NextFile
NextFile = Dir
NextRow = NextRow + 1
Wend
End Sub