An implementation of Visual Basic that is built into Microsoft products.
Hi @Bridget Shoulders ,
The error "Compile error: Invalid outside procedure" occurs because the code you pasted is not enclosed within a valid procedure block (a Sub or Function). You also have an extra End Sub at the very beginning of your code. In VBA, any executable code (like adding items to a ComboBox) must live inside a procedure.
Additionally, near the bottom of your code, you refer to ComboBox.ListRows = 5 lacking the 1 — it should be ComboBox1 to match the rest of the lines.
To fix your issue, clear out your old code and replace it with a properly formulated Subroutine.
For example, if you place the code within the module for the slide containing the ComboBox (e.g., double-clicking the ComboBox in Developer Mode will usually take you there), you can use the DropButtonClick event to populate the list the moment you try to open the dropdown in Slide Show mode:
Private Sub ComboBox1_DropButtonClick()
' Ensure the list hasn't already been populated to prevent duplicates
If ComboBox1.ListCount = 0 Then
ComboBox1.AddItem "Problem"
ComboBox1.AddItem "Acute Respiratory Failure"
ComboBox1.AddItem "Cardiogenic Shock"
ComboBox1.AddItem "Pneumonia"
ComboBox1.AddItem "Hypovolemic Shock"
' Fixed typing error: ComboBox -> ComboBox1
ComboBox1.ListRows = 5
End If
End Sub
Alternatively, if you just want to run a macro manually to populate the dropdown once while designing, you can use:
Sub PopulateComboBox()
ComboBox1.Clear ' clear any old items
ComboBox1.AddItem "Problem"
ComboBox1.AddItem "Acute Respiratory Failure"
ComboBox1.AddItem "Cardiogenic Shock"
ComboBox1.AddItem "Pneumonia"
ComboBox1.AddItem "Hypovolemic Shock"
ComboBox1.ListRows = 5
End Sub
To run this manual setup, just click anywhere inside the Sub PopulateComboBox() and press F5 or click the green "Run" arrow in the VBA Editor toolbar.
If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance or provide feedback.
Thank you.