Hallo,
ah da kommen wir der Sache näher, Du willst in derselben Prozedur auf die Form zugreifen, die hast Du ja schon mit dem Auflistungs-Objekt am Wickel, also verfährst Du für den Zugriff auf das Label genauso:
Option Explicit
Private lstrFrmName As String
Public Sub prcInit()
Const vbext_ct_MSForm As Long = 3
Dim objVBComponent As Object
lstrFrmName = "UserForm1"
For Each objVBComponent In Application.VBE.ActiveVBProject.VBComponents
With objVBComponent
If .Type = vbext_ct_MSForm And _
.Name = lstrFrmName Then Exit For
End With
Next
If Not objVBComponent Is Nothing Then
MsgBox "Das Formular '" & lstrFrmName & "' wurde bereits importiert", vbExclamation
Set objVBComponent = Nothing
Else
Call prcImportTest
End If
End Sub
Private Sub prcImportTest()
Dim strSourcePath As String, strTargetPath As String
Dim strFrmName As String
With ThisDocument
strSourcePath = .Path & "\source_Form_Import.docm"
strTargetPath = .FullName
End With
Application.OrganizerCopy Source:=strSourcePath, Destination:=strTargetPath, _
Name:=lstrFrmName, Object:=wdOrganizerObjectProjectItems
With UserForms.Add(lstrFrmName)
.Label1.Caption = "Neu"
.Show
End With
End Sub
Auf das UserForm1-Objekt könntest Du über einen Timer zugreifen, dann wird kein Fehler geworfen; alles andere wie oben:
Private Sub prcImportTest()
Dim strSourcePath As String, strTargetPath As String
Dim strFrmName As String
With ThisDocument
strSourcePath = .Path & "\source_Form_Import.docm"
strTargetPath = .FullName
End With
Application.OrganizerCopy Source:=strSourcePath, Destination:=strTargetPath, _
Name:=lstrFrmName, Object:=wdOrganizerObjectProjectItems
Application.OnTime When:=Now, Name:="prcTimer"
End Sub
Private Sub prcTimer()
With UserForm1
.Label1.Caption = "Neu"
.Show
End With
End Sub
Gruß,
|