Informationen und Beispiele zum Thema MsgBox | |
---|---|
![]() |
MsgBox-Seite mit Beispielarbeitsmappe aufrufen |
Hallo zusammen,
wie kann ich bitte per Makro in einer TXT-Datei nach [/Main] (es steht nicht immer in selbe Zeile) suchen, dann aus der Zeile da drunter den Wert aus eckigen Klammern auslesen, danach soll aus der Zeile da drunter der erste Zahl vor dem Komma ebenfalls ausgelesen werden und beide in einem MsgBox angezeigt werden. Im Beispiel müsste "Esprit" und "18" ausgegeben werden.
[Main]
Path_template=M:\projekte\2020\vorlagen\template_einhaluf.vor
Path_excel=T:\Export\Berichte\test.xlsx
Show=1
Silent=1
[/Main]
[Esprit]
18,1
Beste Grüße,
Sergej
Sub Schaltfläche1_Klicken() Dim raFund As Range, strWert1 As String, strWert2 As String Set raFund = Columns("A").Find(what:="[/Main]", LookIn:=xlValues, lookat:=xlWhole) If Not raFund Is Nothing Then strWert1 = raFund.Offset(1) strWert2 = raFund.Offset(2) strWert1 = Replace(strWert1, "[", "") strWert1 = Replace(strWert1, "]", "") MsgBox strWert1 & " " & Split(strWert2, ",")(0) Else MsgBox "Der Suchbegriff /Main wurde nicht gefunden." End If Set raFund = Nothing End SubGruß Werner
Sub ReadTXT() Dim iFile As Integer Dim sSearch As String, sTxt As String Dim sFile As String iFile = FreeFile sFile = "M:\projekte\2020\Import\Master.txt" sSearch = "[/Main]" Open sFile For Input As iFile Do Until EOF(1) Input #iFile, sTxt If InStr(sTxt, sSearch) Then sTxt = Replace(sTxt, "[", "") sTxt = Replace(sTxt, "]", "") Debug.Print "Gefunden: " & sTxt Exit Do End If Loop Close iFile End SubBeste Grße,
Sub ReadTXT() Dim iFile As Integer Dim sSearch As String, sTxt As String Dim sFile As String iFile = FreeFile sFile = "M:\projekte\2020\Import\Master.txt" sSearch = "[/Main]" Open sFile For Input As iFile Do Until EOF(1) Input #iFile, sTxt If InStr(sTxt, sSearch) Then sTxt = Replace(sTxt, "[", "") sTxt = Replace(sTxt, "]", "") Debug.Print "Gefunden: " & sTxt Exit Do End If Loop Close iFile End SubBeste Grüße,
ReadTXT() Dim iFile As Integer Dim sSearch As String, sTxt As String, sZeile As String Dim sFile As String iFile = FreeFile sFile = "M:\projekte\2020\Import\Master.txt" sSearch = "[/Main]" Open sFile For Input As iFile Do Until EOF(1) Input #iFile, sTxt If InStr(sTxt, sSearch) Then Input #iFile, sTxt sTxt = Replace(sTxt, "[", "") sTxt = Replace(sTxt, "]", "") MsgBox sTxt Input #iFile, sTxt MsgBox Split(sTxt, ",")(0) Exit Do End If Loop Close iFile End SubBeste Grüße,