In Word gibt es Textfelder als Eingabefelder für Werte.
Wie kann man die Textfelder zur Laufzeit in vba Makro
Code ermitteln und als Feld auswerten ?
Vba:
Ein TextFeld wird in Word als Word Document ->ContentControl verwendet.
Wenn man ein Textfeld in Word vba Code verwenden möchte,
dann muss man einen Loop durch alle ContentControls machen und nach einem Tag
suchen, welches man dem Control eingesetzt hat.
Es gibt mehrere mehrere ContentControl Typen, wobei der
meiste Type ContentControl.Type=wdContentControl.wdContentControlText ist.
Word Verision seit 2010
Word TextFelder
Eingabefelder einstellen
Die Textfelder werden angepasst, indem man ein
Textelement auswählt und dann in der Word Menü (Ribbonbar)-> Entwickler-Tab
auf Eigenschaften wählt.
Unter Tag kann man dem Control einen Namen vergeben.
Vba Code zum Ermitteln eines Word Text Eingabeldes
Private Sub BtnPhotos_Click()
'----<
BtnPhotos_Click() >----
Dim sPfad As String
sPfad = get_Word_ContenField_as_Text("tbxPfad")
MsgBox "Found=" & sPfad
Exit Sub
init_Elements 'get doc and tables
Insert_Photos
'----</
BtnPhotos_Click() >----
End Sub
'====< Helper functions >====
Private Function get_Word_ContenField_as_Text(ByVal sControl_Tag As String)
'--------<
get_Word_ContenField_as_Text(tag as string) >--------
'*find
textbox in word document and give back the value
'tag=tbxPfad,
Type weContenControlText
'<
document >
Dim doc As Document
Set doc =
Application.ActiveDocument
'</
document >
Dim sText As String
sText = ""
'----<
@Loop: ContentControls >----
Dim word_ContentControl As ContentControl
For Each word_ContentControl In doc.ContentControls
If word_ContentControl.Tag Like sControl_Tag Then
'--< Control found >--
If word_ContentControl.Type =
wdContentControlText Then
sText =
word_ContentControl.Range.Text
ElseIf word_ContentControl.Type =
wdContentControlDropdownList Then
sText =
word_ContentControl.Range.Text
Exit For
End If
'--</ Control found >--
End If
Next
'----</
@Loop: ContentControls >----
'<
output >
get_Word_ContenField_as_Text = sText
'</
output >
'--------</
get_Word_ContenField_as_Text(tag as string) >--------
End Function
'====</ Helper functions
>====
|