ich habe in meiner Datei mehrere Makros.
z.B. suchbegriff = UF_Buchung.TextBox12
Kann man den Namen UF_Buchung durch einen Wert aus Zelle einer Tabelle übernehmen?
Besten Dank für eure Hilfe.
Gruss
Peter
UF_Buchung.Caption = Sheets("Tabelle1").Range("A1")
Wenn der TextBox12 der Zellinhalt zugewiesen werden soll, geht es so:UF_Buchung.TextBox12 = Sheets("Tabelle1").Range("A1")
Viele GrüßeSub Auswahl_der_Gesamtkonten_Überschriften_einfügen_Gesamtkonto_Test()
Dim rng As Range
Dim i As String
Dim suchbegriff As String
Dim UFName As String 'neu eingefügt
UFName = Worksheets("Hilfstabelle2").Range("P5").Value 'neu eingefügt
'suchbegriff = UF_Buchung.TextBox12 '= Orginal
suchbegriff = UserForms(UFName).TextBox12 'neu eingefügt - Fehlermeldung
Worksheets("Hilfstabelle").Activate
Set rng = ActiveSheet.Range("A2:A201").Find(suchbegriff)
If rng Is Nothing Then
MsgBox "Nichts gefunden"
Exit Sub
End If
'MsgBox "Zeile: " & rng.Row & "; Adresse: " & rng.Address
'i wählt die akuelle gesuchte und markierte Zeile
i = rng.Row
Range(Cells(i, 4), Cells(i, 14)).Copy
'fügt die kopierten Daten in Gesamtkonto Zeile2 ein
Sheets("Gesamtkonto").Cells(2, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Gesamtkonto").Activate
End Sub
Sub Auswahl_der_Gesamtkonten_Überschriften_einfügen_Gesamtkonto_Test()
Dim rng As Range
Dim i As String
Dim suchbegriff As String
Dim objUserForm As UserForm
Dim UFName As String 'neu eingefügt
UFName = Worksheets("Hilfstabelle2").Range("P5").Value 'neu eingefügt
Set objUserForm = FindUserFormByName(UFName)
If objUserForm Is Nothing Then
MsgBox "Es gibt kein geöffnetes UserForm mit dem Namen " & UFName, vbExclamation
Exit Sub
End If
suchbegriff = objUserForm.TextBox12
Worksheets("Hilfstabelle").Activate
Set rng = ActiveSheet.Range("A2:A201").Find(suchbegriff)
If rng Is Nothing Then
MsgBox "Nichts gefunden"
Exit Sub
End If
'MsgBox "Zeile: " & rng.Row & "; Adresse: " & rng.Address
'i wählt die akuelle gesuchte und markierte Zeile
i = rng.Row
Range(Cells(i, 4), Cells(i, 14)).Copy
'fügt die kopierten Daten in Gesamtkonto Zeile2 ein
Sheets("Gesamtkonto").Cells(2, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Gesamtkonto").Activate
End Sub
Function FindUserFormByName(strUserFormName As String) As Object
Dim i As Integer
Set FindUserFormByName = Nothing
For i = 0 To UserForms.Count - 1
If UserForms(i).Name = strUserFormName Then
Set FindUserFormByName = UserForms(i)
Exit Function
End If
Next
End Function
Viele Grüße'...
Dim suchbegriff As String, UFName As String
UFName = Worksheets("Hilfstabelle2").Range("P5").Value 'neu eingefügt
suchbegriff = UserForms.Add(UFName).TextBox12.Value
'...
suchbegriff = UserForms(UFName).TextBox12
suchbegriff = UserForms.Add(UFName).TextBox12.Value
UserForm Object
A UserForm object is a window or dialog box that makes _
up part of an application's user interface.
The UserForms collection is a collection whose elements represent each loaded
UserForm in an application. The UserForms collection has a Count property, an Item property,
and an Add method. Count specifies the number of elements _
in the collection;
Item (the default member) specifies a specific collection member;
and Add places a new UserForm element in the collection.
Syntax
UserForm
UserForms[.Item](index)
The placeholder index represents an integer with a range from 0 to UserForms.Count – 1.
Item is the default member of the UserForms collection and need not be specified.
_
Remarks
You can use the UserForms collection to iterate through all loaded user forms in an application.
It identifies an intrinsic global variable named UserForms.
You can pass UserForms(index) to a function whose argument is specified as a UserForm class.