Hello.
I have a number of MS Word documents that all have the same layout.
I wish:
1- open each document
2- browse through all the listboxes in each document
3-For each listbox:
I want to retrieve the value that is selected
For the moment I have managed to program the first part: Loop on several Word documents:
Code:
Public wordApp As New Word.Application
Public Sub Ouvrir_Tout_Les_Fichiers()
Dim Fichier_Objet As String
titre = "Ouvrir le(s) fichier(s)"
Filt = "Fichier(s) a integrer (*.docm;*.doc;*.docx),*.docm;*.doc;*.docx"
fileToOpen = Application.GetOpenFilename(FileFilter:=Filt, Title:=titre, MultiSelect:=True)
For I = LBound(fileToOpen) To UBound(fileToOpen)
FilePath = Left(fileToOpen(I), InStrRev(fileToOpen(I), "\"))
Fichier_Objet = Mid(fileToOpen(I), InStrRev(fileToOpen(I), "\") + 1)
Set wordApp = CreateObject("Word.Application")
wordApp.Documents.Open fileToOpen(I)
wordApp.Visible = True
File_Name = UBound(fileToOpen)
Call _2browse_through_all_the_listboxes_in_each_document(I, Fichier_Objet)
wordApp.Documents.Close
wordApp.Quit
Next I
End Sub
In each document I try to browse all the listboxes!
Apparently the listboxes are "ContentControlListEntry" objects...
https://docs.microsoft.com/fr-fr/off...ntrollistentry... which are contained in "ContentControl" objects
https://docs.microsoft.com/fr-fr/off...ntent-controls
Code:
Public Sub _2browse_through_all_the_listboxes_in_each_document(I, Fichier_Objet)
Dim objCc As ContentControl
Dim objLe As ContentControlListEntry
Debug.Print Fichier_Objet
For Each objCc In wordApp.ActiveDocument.ContentControls
For Each objLe In objCc.DropdownListEntries
Debug.Print objLe.Text
Debug.Print objLe.Index
Debug.Print objLe.Value
'Debug.Print objLe.Creator
Next
Next
End Sub
I try to browse all the listboxes (objCc.DropdownListEntries) and extract the value that has been selected. But it's impossible to find the right property!
I managed to extract objLe.Text; objLe.Index; objLe.Value ... but I can't find anything that looks like the value that was chosen in the list box. (maybe the visible property = true ... or something like that??)
...
I managed to successfully extract the values of the "checkboxes" and the values of the "user fields"... but I really block on these "listboxes":
Code:
Public Sub Extract_user_fields_and_checkbox(I, Fichier_Objet)
Dim ch As Field
Dim Ctrl As ContentControl
Debug.Print Fichier_Objet
For Each ch In wordApp.ActiveDocument.Fields
If ch.Type = "70" Then
Debug.Print "Index ", ch.Index
Debug.Print "Result ", ch.Result
Debug.Print "Type ", ch.Type
End If
Next ch
For Each Ctrl In wordApp.ActiveDocument.ContentControls
If Ctrl.Type = "8" Then
If Ctrl.Checked = True Then
Debug.Print Ctrl.Tag
Debug.Print Ctrl.ID
Debug.Print "True"
Else
Debug.Print Ctrl.Tag
Debug.Print Ctrl.ID
Debug.Print "False"
End If
End If
Next
End Sub
Does anyone have any idea how to proceed?
Thank you very much