Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-07-2022, 02:06 PM
Jeff_Reach Jeff_Reach is offline Dependent Dropdown Argument Is Way Too Long [Word 365 - VBA] Windows 11 Dependent Dropdown Argument Is Way Too Long [Word 365 - VBA] Office 2021
Novice
Dependent Dropdown Argument Is Way Too Long [Word 365 - VBA]
 
Join Date: Apr 2022
Posts: 8
Jeff_Reach is on a distinguished road
Question Dependent Dropdown Argument Is Way Too Long [Word 365 - VBA]

All,




I'm currently trying to utilize the below formula attained from the referenced discussion to create a dependent drop down that contains all of the possible sub-chapter values. Unfortunately there are way to many sub-chapter values to fit on a single line for several of the chapters. How I know this is that VBA comes up with a pop-up saying that the the line of code is "too long."


To shorten the line, and also help make the code readable I have attempted using combinations of &_ and _ to no avail. While I've seen on several sites that I should break up the line of text into separate variables? or arrays? I have repeatedly failed to make this work without breaking Macropod's code. Therefore, I'm hopeful that someone out there can please tell me how to "shrink" or better organize the excessively long line of StrOut values.





Note: I've modified the chapter and sub-chapter names below to protect the specific purpose of the document. Meaning that in the actual code there isn't a [...] only a lot more subchapters.


Note 2: I think this question is sufficiently different than the original discussion. Therefore instead of tying my questions directly to the other discussion as a response I thought it would be best to create a new discussion topic.



Reference: https://www.msofficeforums.com/word/...wn-option.html





Code:
Option Explicit
Dim StrOption As String

Private Sub Document_ContentControlOnEnter(ByVal CCtrl As ContentControl)
If CCtrl.Title = "R1Chapter" Then StrOption = CCtrl.Range.Text
End Sub

Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim i As Long, StrOut As String
With CCtrl
  If .Title = "R1Chapter" Then
      If StrOption = .Range.Text Then Exit Sub
    Select Case .Range.Text
      Case "Chapter 1"
        StrOut = "Subchapter 1|Subchapter 2|Subchapter 3....
      Case Else
        .Type = wdContentControlText
        .Range.Text = ""
        .Type = wdContentControlDropdownList
    End Select
    With ActiveDocument.SelectContentControlsByTitle("R1Subchapter")(1)
      .DropdownListEntries.Clear
      For i = 0 To UBound(Split(StrOut, "|"))
        .DropdownListEntries.Add Split(StrOut, "|")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With

  End If
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
 

Tags
dependent-drop down



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dependent Dropdown Argument Is Way Too Long [Word 365 - VBA] Content Controls - Dependent Dropdown someazguy Word VBA 14 02-05-2023 08:01 PM
Link CC dropdown to dependent dropdown AND text box trailrunnertcm Word VBA 4 02-11-2021 08:04 AM
Absolute Dependent Dropdown lists probinson76 Word VBA 5 06-07-2020 03:59 PM
Dependent Dropdown Argument Is Way Too Long [Word 365 - VBA] Populate Dependent Word Dropdown List from Excel Narcissus Word VBA 1 05-05-2020 02:55 PM
Dropdown dependent text JakeLRL Word VBA 7 04-07-2016 08:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:55 AM.


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