arotciv
Goto Top

Excel Textkonvertierungs-Assistent läßt sich nicht unterdrücken

Hallo,

ich habe hier in einer Excelmappe ein Makro, dass mir eine Textdatei in eine neue Arbeitsmappe einfügt.
Ich würde gerne den lästigen Textkonvertierungs Assistenten umgehen, oder per Makro mit den abgefragten Infos füttern, damit er nicht mehr erscheint.
Leider hilft das Abschalten der Warnungen dabei nicht.

Mein Makro sieht derzeit so aus:
Sub NTI_ADDY()

    Dim DestBook As Workbook, SourceBook As Workbook
    Dim DestCell As Range
    Dim RetVal As Boolean
  
  For i = 1 To 20 Step 1
        Set NewSheet = Worksheets.Add
        NewSheet.Name = "NTI-IMPORT" & i  

             ' Turn off screen updating.  
                               Application.ScreenUpdating = False
                               Application.DisplayAlerts = False
              ' Set object variables for the active book and active cell.  
                                 Set DestBook = ActiveWorkbook
                                 Set DestCell = ActiveCell

              ' Show the Open dialog box.  
                                 RetVal = Application.Dialogs(xlDialogOpen).Show("*RT60*Report*.txt")  

             ' If Retval is false (Open dialog canceled), exit the procedure.  
                                If RetVal = False Then Exit Sub

             ' Set an object variable for the workbook containing the text file.  
                                Set SourceBook = ActiveWorkbook

             ' Copy the contents of the entire sheet containing the text file.  
                    
                                  Range(Range("A1"), Range("A1").SpecialCells(xlLastCell)).Copy  
           
            ' Activate the destination workbook and paste special the values  
             ' from the text file.  
                                   DestBook.Activate
                                  DestCell.PasteSpecial Paste:=xlPasteValuesAndNumberFormats 'Paste:=xlValues  

                ' Close the book containing the text file.  
                                  SourceBook.Close False
                                 'Application.DisplayAlerts = True  

                '  Weitere Messung laden  

        Auswahl = MsgBox("Weiteren Messpunkt einfügen?", vbYesNo + vbQuestion, "NTI LOAD POS 2")  
        
        If Auswahl = vbNo Then Exit For
  Next i
  Application.DisplayAlerts = True
End Sub

[Edit Biber] Codeformatierung nachgezogen. [/Edit]

Content-Key: 295769

Url: https://administrator.de/contentid/295769

Printed on: April 19, 2024 at 09:04 o'clock

Mitglied: 114757
114757 Feb 10, 2016 updated at 12:54:41 (UTC)
Goto Top
Moinsens.
Einfach mal den Makro-Recorder angeworfen, dann wäre der Thread obsolet gewesen face-wink

With DestBook.QueryTables.Add(Connection:="TEXT;" & "PFAD DEINER DATEI", Destination:=DestBook.Range("$A$1"))  
                .Name = "import"  
                .FieldNames = True
                .AdjustColumnWidth = True
                .RefreshPeriod = 0
                .TextFilePlatform = 1252
                .TextFileStartRow = 1
                .TextFileParseType = xlDelimited
                .TextFileTextQualifier = xlTextQualifierDoubleQuote
                .TextFileSemicolonDelimiter = True
                .Refresh BackgroundQuery:=False
                .Delete
End With
Eigenschaften für den Import natürlich anpassen (Delimiter etc. pp)
https://msdn.microsoft.com/de-de/library/office/ff837764.aspx

Gruß jodel32
Member: arotciv
arotciv Feb 10, 2016 at 13:11:54 (UTC)
Goto Top
Moin,

vielen Dank, aber der Makrorecorder hat mir das nicht ausgeworfen. Das hatte ich versucht.
Mitglied: 126919
126919 Feb 10, 2016 updated at 13:17:57 (UTC)
Goto Top
Hi.
Zitat von @arotciv:
vielen Dank, aber der Makrorecorder hat mir das nicht ausgeworfen. Das hatte ich versucht.
dazu musst du das über Tab: Daten --> Externe Daten abrufen --> Text machen face-wink

fk
Member: arotciv
arotciv Feb 10, 2016 at 13:29:31 (UTC)
Goto Top
Hallo Jodel32 und Flachkoepper,

ich bin anscheinend leider nicht in der Lage den Code von Jodel32 in meinen Code richtig zu integrieren. An welcher Stelle binde ich das ein?

Hier nochmal der Code:

Sub NTI_LOADER()

    Dim DestBook As Workbook, SourceBook As Workbook
    Dim DestCell As Range
    Dim RetVal As Boolean
  
  For i = 20 To 1 Step -1
        Set NewSheet = Worksheets.Add
        NewSheet.Name = "NTI-IMPORT" & i  

             ' Turn off screen updating.  
                     Application.ScreenUpdating = False
                     Application.DisplayAlerts = False
              ' Set object variables for the active book and active cell.  
                     Set DestBook = ActiveWorkbook
                     Set DestCell = ActiveCell

              ' Show the Open dialog box.  
                     RetVal = Application.Dialogs(xlDialogOpen).Show("*RT60*Report*.txt")  

             ' If Retval is false (Open dialog canceled), exit the procedure.  
                     If RetVal = False Then Exit Sub

             ' Set an object variable for the workbook containing the text file.  
                      Set SourceBook = ActiveWorkbook

             ' Copy the contents of the entire sheet containing the text file.  
                    
                      Range(Range("A1"), Range("A1").SpecialCells(xlLastCell)).Copy  
           
            ' Activate the destination workbook and paste special the values  
             ' from the text file.  
                      DestBook.Activate
                      DestCell.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
             ' Close the book containing the text file.  
                         SourceBook.Close False
                 
                 '  Weitere Messung laden  

        Auswahl = MsgBox("Weiteren Messpunkt einfügen?", vbYesNo + vbQuestion, "NTI LOAD POS 2")  
        
        If Auswahl = vbNo Then Exit For
   Next i
  Application.DisplayAlerts = True
End Sub