Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-03-2019, 09:10 AM
Wire.Lless Wire.Lless is offline Scan all existing listBoxes in a document and retrieve the selected value. Windows 8 Scan all existing listBoxes in a document and retrieve the selected value. Office 2010
Novice
Scan all existing listBoxes in a document and retrieve the selected value.
 
Join Date: Apr 2019
Posts: 2
Wire.Lless is on a distinguished road
Default Scan all existing listBoxes in a document and retrieve the selected value.

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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Scan all existing listBoxes in a document and retrieve the selected value. Retrieve a word from another document vestergaard Word 3 02-08-2018 10:30 AM
Scan all existing listBoxes in a document and retrieve the selected value. Retrieve the last activated document name. 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
Scan all existing listBoxes in a document and retrieve the selected value. Scan Document into excel 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft