Hallo,
ja das das geht in Excel geschmeidiger, in Word fehlt die OLEObjects-Collection, Du könntest Dir allerdings Deine eigene Checkbox-Collection bauen, dann muß man den Weg nur einmal gehen:
Code in das Dokumentenmodul ('ThisDocument'):
Option Explicit
Private Sub Document_Close()
Call Terminate_Collection
End Sub
Private Sub Document_Open()
Call Init_Collection
End Sub
Code in ein Standardmodul:
Option Explicit
Option Private Module
Private lcolCheckBoxes As Collection
Public Sub Init_Collection()
Dim objShape As Shape
Set lcolCheckBoxes = New Collection
For Each objShape In ThisDocument.Shapes
With objShape.OLEFormat
If .ClassType = "Forms.CheckBox.1" Then _
Call lcolCheckBoxes.Add(Item:=.Object, Key:=.Object.Name)
End With
Next
End Sub
Public Sub Terminate_Collection()
Set lcolCheckBoxes = Nothing
End Sub
Public Property Get CheckBoxes() As Collection
Set CheckBoxes = lcolCheckBoxes
End Property
Code in ein weiteres Standard-Test-Modul:
Option Explicit
Public Sub test()
If Not CheckBoxes Is Nothing Then _
MsgBox CheckBoxes("CheckBox1").Value
End Sub
Mappe dann als .docm-Datei speichern, schließen >>> neu öffnen...
Gruß und frohe Ostern ebenso...
|