Thema Datum  Von Nutzer Rating
Antwort
26.05.2016 15:30:34 Sdravi
NotSolved
26.05.2016 17:51:51 Gast71200
NotSolved
Rot UserForm Daten auslesen und anzeigen
26.05.2016 20:03:30 Gast16080
NotSolved
26.05.2016 22:04:16 Gast77476
NotSolved
27.05.2016 04:38:08 Gast49651
NotSolved
27.05.2016 18:39:40 Gast39404
NotSolved
27.05.2016 19:28:19 Gast31470
Solved
29.05.2016 15:09:12 Gast11855
NotSolved
29.05.2016 16:10:11 Gast69544
NotSolved

Ansicht des Beitrags:
Von:
Gast16080
Datum:
26.05.2016 20:03:30
Views:
759
Rating: Antwort:
  Ja
Thema:
UserForm Daten auslesen und anzeigen

Hy mein VBA ist miserabel :-(

zurzeit habe ich das hier das reicht aber noch nicht aus

Option Explicit

Private Const ROOT_FOLDER As String = "C:\Users\asus\Desktop\excel\"

Private Sub CommandButton1_Click()
    
    Dim objWorbook As Workbook
    
    If ComboBox1.ListIndex > -1 Then
        
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        
        Set objWorbook = Workbooks.Open(Filename:= _
            ROOT_FOLDER & ComboBox1.Text, UpdateLinks:=0, ReadOnly:=True)
        
        Call objWorbook.Worksheets(1).Range("A3:F3").Copy( _
            Destination:=ThisWorkbook.Worksheets(1).Cells(4, 1))
        
        Call objWorbook.Close(SaveChanges:=False)
        
        Set objWorbook = Nothing
        
        With Application
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End If
    
     If ComboBox2.ListIndex > -1 Then
        
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        
        Set objWorbook = Workbooks.Open(Filename:= _
            ROOT_FOLDER & ComboBox2.Text, UpdateLinks:=0, ReadOnly:=True)
        
        Call objWorbook.Worksheets(1).Range("A3:F3").Copy( _
            Destination:=ThisWorkbook.Worksheets(1).Cells(5, 1))
        
        Call objWorbook.Close(SaveChanges:=False)
        
        Set objWorbook = Nothing
        
        With Application
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End If
    
    If ComboBox3.ListIndex > -1 Then
        
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        
        Set objWorbook = Workbooks.Open(Filename:= _
            ROOT_FOLDER & ComboBox3.Text, UpdateLinks:=0, ReadOnly:=True)
        
        Call objWorbook.Worksheets(1).Range("A3:F3").Copy( _
            Destination:=ThisWorkbook.Worksheets(1).Cells(6, 1))
        
        Call objWorbook.Close(SaveChanges:=False)
        
        Set objWorbook = Nothing
        
        With Application
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End If
    
    If ComboBox4.ListIndex > -1 Then
        
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        
        Set objWorbook = Workbooks.Open(Filename:= _
            ROOT_FOLDER & ComboBox4.Text, UpdateLinks:=0, ReadOnly:=True)
        
        Call objWorbook.Worksheets(1).Range("A3:F3").Copy( _
            Destination:=ThisWorkbook.Worksheets(1).Cells(7, 1))
        
        Call objWorbook.Close(SaveChanges:=False)
        
        Set objWorbook = Nothing
        
        With Application
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End If
    
    If ComboBox5.ListIndex > -1 Then
        
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        
        Set objWorbook = Workbooks.Open(Filename:= _
            ROOT_FOLDER & ComboBox5.Text, UpdateLinks:=0, ReadOnly:=True)
        
        Call objWorbook.Worksheets(1).Range("A3:F3").Copy( _
            Destination:=ThisWorkbook.Worksheets(1).Cells(8, 1))
        
        Call objWorbook.Close(SaveChanges:=False)
        
        Set objWorbook = Nothing
        
        With Application
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End If
    
    If ComboBox6.ListIndex > -1 Then
        
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        
        Set objWorbook = Workbooks.Open(Filename:= _
            ROOT_FOLDER & ComboBox6.Text, UpdateLinks:=0, ReadOnly:=True)
        
        Call objWorbook.Worksheets(1).Range("A3:F3").Copy( _
            Destination:=ThisWorkbook.Worksheets(1).Cells(9, 1))
        
        Call objWorbook.Close(SaveChanges:=False)
        
        Set objWorbook = Nothing
        
        With Application
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End If
End Sub

Private Sub CommandButton2_Click()
    Call Unload(Me)
End Sub

Private Sub UserForm_Activate()
    
    Dim strFilename As String
    
    strFilename = Dir$(ROOT_FOLDER & "*.xls")
    
    Do Until strFilename = vbNullString
        
        Call ComboBox1.AddItem(pvargItem:=strFilename)
        Call ComboBox2.AddItem(pvargItem:=strFilename)
        Call ComboBox3.AddItem(pvargItem:=strFilename)
        Call ComboBox4.AddItem(pvargItem:=strFilename)
        Call ComboBox5.AddItem(pvargItem:=strFilename)
        Call ComboBox6.AddItem(pvargItem:=strFilename)
        strFilename = Dir$
        
    Loop
End Sub

Ich habe in den Dateien immer 6 Tabellen jetzt mochte ich im UserForm 6 OptionButtons einbauen um dan auszuwählen aus welcher Tabele er mir die Daten zeigen soll.

Und der Obere Code geht bestimmt auch schlanker oder?

 

mfg

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
26.05.2016 15:30:34 Sdravi
NotSolved
26.05.2016 17:51:51 Gast71200
NotSolved
Rot UserForm Daten auslesen und anzeigen
26.05.2016 20:03:30 Gast16080
NotSolved
26.05.2016 22:04:16 Gast77476
NotSolved
27.05.2016 04:38:08 Gast49651
NotSolved
27.05.2016 18:39:40 Gast39404
NotSolved
27.05.2016 19:28:19 Gast31470
Solved
29.05.2016 15:09:12 Gast11855
NotSolved
29.05.2016 16:10:11 Gast69544
NotSolved