![]() |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
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: For the moment I have managed to program the first part: Loop on several Word documents:I want to retrieve the value that is selected 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 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 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 Thank you very much |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
vestergaard | Word | 3 | 02-08-2018 10:30 AM |
![]() |
eduzs | Word VBA | 1 | 08-22-2017 03:11 PM |
Can i make excel retrieve selected text? | peterpiper | Excel | 1 | 07-11-2017 03:49 AM |
![]() |
mtwa | Excel | 1 | 04-21-2016 09:01 PM |
Data from hidden internal tables feeding listboxes in same Word Document | marksm33 | Word VBA | 2 | 02-21-2014 07:10 PM |