![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hello!
I am trying to create cascading drop-down menus in Word, and I have never done those before. In doing some research, I have adapted code, but I am getting an error message and then the drop downs are not dependent. I am not sure how to fix the code so that it works for the one parent menu and the four dependent menus. The error I get is "Compile error: Expected End With" and here is the code I currently have (with the data updated to be generic): Code:
Option Explicit
Dim StrOption As String
Private Sub Document_ContentControlOnEnter(ByVal CCtrl As ContentControl)
If CCtrl.Title = "ProductServices" Then StrOption = CCtrl.Range.Text
If CCtrl.Title = "Unit" 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 = "ProductServices" Then
If StrOption = .Range.Text Then Exit Sub
Select Case .Range.Text
Case "1"
StrOut = "Per Hotel Vendor Chain"
Case "2"
StrOut = "Per Hotel Vendor Chain"
Case "3"
StrOut = "Per Hotel Vendor Chain"
Case "4"
StrOut = "Per Hotel Vendor Chain"
Case "5"
StrOut = "Per Hotel Vendor Chain"
Case "6"
StrOut = "Per Hotel Vendor Chain"
Case "7"
StrOut = "Per Hotel Vendor Chain"
Case "8"
StrOut = "Per Hotel Vendor Chain"
Case "9"
StrOut = "Per Property / per core"
Case "10"
StrOut = "Per Hotel Vendor Chain"
Case "11"
StrOut = "Per Hotel Vendor Chain"
Case "12"
StrOut = "Per Hotel Vendor Chain"
Case "13"
StrOut = "Per Hotel Vendor Chain"
Case "14"
StrOut = "Per Hotel Vendor Chain"
Case "15"
StrOut = "Per Hotel Vendor Chain"
Case "16"
StrOut = "Per Hotel Vendor Chain"
Case "17"
StrOut = "Per Hotel Vendor Chain"
Case "18"
StrOut = "Per Hotel Vendor Chain"
Case "19"
StrOut = "Per License"
StrOut = "N/A"
Case "20"
StrOut = "Per License"
StrOut = "N/A"
Case "21"
StrOut = "Per License"
StrOut = "N/A"
Case "22"
StrOut = "N/A"
Case "23"
StrOut = "N/A"
Case "24"
StrOut = "Per License"
Case "25"
StrOut = "Per License"
Case "26"
StrOut = "Per Hotel Vendor Chain"
Case Else
.Type = wdContentControlText
.Range.Text = ""
.Type = wdContentControlDropdownList
End Select
With ActiveDocument.SelectContentControlsByTitle("Unit")(1)
.DropdownListEntries.Clear
.DropdownListEntries.Add .PlaceholderText
For i = 0 To UBound(Split(StrOut, ","))
.DropdownListEntries.Add Split(StrOut, ",")(i)
Next
.Type = wdContentControlText
.Range.Text = ""
.Type = wdContentControlDropdownList
End With
With ActiveDocument.SelectContentControlsByTitle("Recurringfee")(1)
.DropdownListEntries.Clear
.Type = wdContentControlText
.Range.Text = ""
.Type = wdContentControlDropdownList
End With
End If
If .Title = "ProductService" Then
If StrOption = .Range.Text Then Exit Sub
Select Case .Range.Text
Case "1"
StrOut = "N/A"
Case "2"
StrOut = "N/A"
Case "3"
StrOut = "N/A"
Case "4"
StrOut = "N/A"
Case "5"
StrOut = "N/A"
Case "6"
StrOut = "N/A"
Case "7"
StrOut = "N/A"
Case "8"
StrOut = "$10.00"
Case "9"
StrOut = "$25.00"
Case "10"
StrOut = "$100.00"
Case "11"
StrOut = "N/A"
Case "12"
StrOut = "N/A"
Case "13"
StrOut = "N/A"
Case "14"
StrOut = "N/A"
Case "15"
StrOut = "N/A"
Case "16"
StrOut = "N/A"
Case "17"
StrOut = "N/A"
Case "18"
StrOut = "N/A"
Case "19"
StrOut = "$10.00"
Case "20"
StrOut = "$180.00"
Case "21"
StrOut = "$60.00"
Case "22"
StrOut = "$30.00"
Case "23"
StrOut = "$48.00"
Case "24"
StrOut = "N/A"
Case "25"
StrOut = "N/A"
Case "26"
StrOut = "N/A"
Case Else
.Type = wdContentControlText
.Range.Text = ""
.Type = wdContentControlDropdownList
End Select
With ActiveDocument.SelectContentControlsByTitle("Recurringfee")(1)
.DropdownListEntries.Clear
.DropdownListEntries.Add .PlaceholderText
For i = 0 To UBound(Split(StrOut, ","))
.DropdownListEntries.Add Split(StrOut, ",")(i)
Next
.Type = wdContentControlText
.Range.Text = ""
.Type = wdContentControlDropdownList
End With
End If
If .Title = "ProductService" Then
If StrOption = .Range.Text Then Exit Sub
Select Case .Range.Text
Case "1"
StrOut = "$20,000.00"
Case "2"
StrOut = "$15,000.00"
Case "3"
StrOut = "$17,500.00"
Case "4"
StrOut = "$10,000.00"
Case "5"
StrOut = "$10,000.00"
Case "6"
StrOut = "$1,000.00"
Case "7"
StrOut = "$1,000.00"
Case "8"
StrOut = "N/A"
Case "9"
StrOut = "N/A"
Case "10"
StrOut = "N/A"
Case "11"
StrOut = "$2,000.00"
Case "12"
StrOut = "$500.00"
Case "13"
StrOut = "$2,000.00"
Case "14"
StrOut = "$2,000.00"
Case "15"
StrOut = "$5,000.00"
Case "16"
StrOut = "$5,000.00"
Case "17"
StrOut = "$2,000.00"
Case "18"
StrOut = "$2,000.00"
Case "19"
StrOut = "$200.00"
Case "20"
StrOut = "$200.00"
Case "21"
StrOut = "$200.00"
Case "22"
StrOut = "N/A"
Case "23"
StrOut = "N/A"
Case "24"
StrOut = "$3,000.00"
Case "25"
StrOut = "$1,000.00"
Case "26"
StrOut = "$500.00"
Case Else
.Type = wdContentControlText
.Range.Text = ""
.Type = wdContentControlDropdownList
End Select
With ActiveDocument.SelectContentControlsByTitle("Onetimefee")(1)
.DropdownListEntries.Clear
.DropdownListEntries.Add .PlaceholderText
For i = 0 To UBound(Split(StrOut, ","))
.DropdownListEntries.Add Split(StrOut, ",")(i)
Next
.Type = wdContentControlText
.Range.Text = ""
.Type = wdContentControlDropdownList
End With
End If
If .Title = "ProductService" Then
If StrOption = .Range.Text Then Exit Sub
Select Case .Range.Text
Case "1"
StrOut = "One-time"
Case "2"
StrOut = "One-time"
Case "3"
StrOut = "One-time"
Case "4"
StrOut = "One-time"
Case "5"
StrOut = "One-time"
Case "6"
StrOut = "One-time"
Case "7"
StrOut = "One-time"
Case "8"
StrOut = "Monthly"
Case "9"
StrOut = "Monthly"
Case "10"
StrOut = "Monthly"
Case "11"
StrOut = "One-time"
Case "12"
StrOut = "One-time"
Case "13"
StrOut = "One-time"
Case "14"
StrOut = "One-time"
Case "15"
StrOut = "One-time"
Case "16"
StrOut = "One-time"
Case "17"
StrOut = "One-time"
Case "18"
StrOut = "One-time"
Case "19"
StrOut = "Monthly for Recurring Fee; One-time for One-time Fee"
Case "20"
StrOut = "Monthly for Recurring Fee; One-time for One-time Fee"
Case "21"
StrOut = "Monthly for Recurring Fee; One-time for One-time Fee"
Case "22"
StrOut = "Monthly"
Case "23"
StrOut = "Monthly"
Case "24"
StrOut = "One-time"
Case "25"
StrOut = "One-time"
Case "26"
StrOut = "One-time"
Case Else
.Type = wdContentControlText
.Range.Text = ""
.Type = wdContentControlDropdownList
End Select
With ActiveDocument.SelectContentControlsByTitle("Billingmode")(1)
.DropdownListEntries.Clear
.DropdownListEntries.Add .PlaceholderText
For i = 0 To UBound(Split(StrOut, ","))
.DropdownListEntries.Add Split(StrOut, ",")(i)
Next
.Type = wdContentControlText
.Range.Text = ""
.Type = wdContentControlDropdownList
End With
End If
Application.ScreenUpdating = True
End Sub
Last edited by macropod; 03-27-2020 at 02:30 PM. Reason: Added code tags |
|
#2
|
||||
|
||||
|
Cross-posted at: Cascading drop-downs in Word - Microsoft Community
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Thanks for making me aware of this! I marked this post as 'solved' since someone commented on the other. I'm not sure how to delete a thread from here!
|
|
#4
|
|||
|
|||
|
We might as well leave it up here so that anyone finding this thread will have a link to the solution.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Needing to learn dependent drop downs and how to still keep the document editable
|
sconeill92 | Word VBA | 12 | 02-21-2020 10:16 AM |
Help with Colour Coding drop downs.
|
Instructionalhelp | Word VBA | 11 | 03-15-2018 10:35 PM |
Lock specific drop downs on a Word Document
|
icarrus | Word | 1 | 09-30-2015 02:07 PM |
| Drop Downs | Suray1911 | Excel | 1 | 09-29-2015 10:31 PM |
Drop-Downs: Run Macro on Exit
|
Andrew H | Word VBA | 15 | 11-16-2012 08:34 AM |