May 3rd, 2004, 02:53 PM
#1
Word VBA Document form....[RESOLVED]
I need to have a dropdown in a word form dropdown automatically...any clue??
The closest I cant get is have it get focus.....
Last edited by Static; May 5th, 2004 at 09:25 AM .
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
May 3rd, 2004, 04:48 PM
#2
Hyperactive Member
How do you mean automatically, when the document is opened or what?
May 3rd, 2004, 05:40 PM
#3
This works in VB. I'm sure it should work in Word.
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const CB_SHOWDROPDOWN = &H14F
Private Sub Command1_Click()
SendMessage cboDropMe.hwnd, CB_SHOWDROPDOWN, ByVal 1, ByVal 0&
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 3rd, 2004, 05:46 PM
#4
Uh, edit that.
Word equilivalent.
VB Code:
Private Sub CommandButton1_Click()
cboDropMe.DropDown
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 4th, 2004, 09:18 AM
#5
Thanks for the reply...but...this isnt a VB form in word...its a document form. (FORMS toolbar)
so the darn things cant be refered to like that... its
ThisDocument.Formfields(x).etc
aaauuughhh!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
May 4th, 2004, 12:27 PM
#6
Ok, try this in a new blank document (add code to ThisDocument
class). Save it, close it, and re-open it and it will automatically add
a dropdown with 10 items, already dropped menu.
VB Code:
Private Sub Document_Open()
Call LoadMe
End Sub
Sub LoadMe()
Dim oFF As FormField
Dim i As Integer
If ActiveDocument.FormFields.Count = 0 Then
ActiveDocument.FormFields.Add ActiveDocument.Range(Start:=0, End:=0), wdFieldFormDropDown
End If
Set oFF = ActiveDocument.FormFields(1)
oFF.DropDown.ListEntries.Clear
For i = 1 To 10
oFF.DropDown.ListEntries.Add "Test " & i, i
Next
ActiveDocument.Protect wdAllowOnlyFormFields
SendKeys "%{DOWN}", True
'oFF.DropDown.Value = 8 'Select the 8th element in the dropdown list.
End Sub
HTH
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 4th, 2004, 01:18 PM
#7
Your close rob,
I tried the sendkeys as well... but, when there are multiple dropdowns...it just jumps to the next dropdown and sets focus. it doesnt drop down!!!!
I have 6 checkboxes...each with a dropdown next to it.
when I click the check box I wanted the dropdown to open...
Best I can get is just set focus to the dropdown.
Oh well....close enough for now.
Thanks for your help
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
May 4th, 2004, 02:32 PM
#8
Ok, here is the solution.
I clear and reload each dropdown when the corresponding
checkbox is checked. This seems to keep focus on the
corresponding line. Then a sendkeys of shift + tab to set the
focus on the correct dropdown and another sendkeys to drop it
down. Micky mouse but it works. I attached my test doc for you to
look at.
VB Code:
Public Sub Check1()
Dim oFF As FormField
Dim i As Integer
If ActiveDocument.FormFields.Item("Check1").CheckBox.Value = True Then
Set oFF = ActiveDocument.FormFields.Item("Dropdown1")
oFF.DropDown.ListEntries.Clear
For i = 1 To 10
oFF.DropDown.ListEntries.Add "Test " & i, i
Next
If ActiveDocument.ProtectionType <> wdAllowOnlyFormFields Then
ActiveDocument.Protect wdAllowOnlyFormFields
End If
SendKeys "+{TAB}", True
SendKeys "%{DOWN}", True
End If
End Sub
Public Sub Check2()
Dim oFF As FormField
Dim i As Integer
If ActiveDocument.FormFields.Item("Check2").CheckBox.Value = True Then
Set oFF = ActiveDocument.FormFields.Item("Dropdown2")
oFF.DropDown.ListEntries.Clear
For i = 2 To 10 Step 2
oFF.DropDown.ListEntries.Add "Test " & i, i / 2
Next
If ActiveDocument.ProtectionType <> wdAllowOnlyFormFields Then
ActiveDocument.Protect wdAllowOnlyFormFields
End If
SendKeys "+{TAB}", True
SendKeys "%{DOWN}", True
End If
End Sub
Public Sub Check3()
Dim oFF As FormField
Dim i As Integer
If ActiveDocument.FormFields.Item("Check3").CheckBox.Value = True Then
Set oFF = ActiveDocument.FormFields.Item("Dropdown3")
oFF.DropDown.ListEntries.Clear
For i = 3 To 10 Step 3
oFF.DropDown.ListEntries.Add "Test " & i, i / 3
Next
If ActiveDocument.ProtectionType <> wdAllowOnlyFormFields Then
ActiveDocument.Protect wdAllowOnlyFormFields
End If
SendKeys "+{TAB}", True
SendKeys "%{DOWN}", True
End If
End Sub
Attached Files
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 5th, 2004, 09:25 AM
#9
thanks Rob, but your sendkey code from before triggered a new Idea...(Which you have just used)
in the on enter macro for the checkbox...
Sendkeys "{TAB}%{DOWN}"
worked perfectly!!
thanks for your help!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
May 5th, 2004, 10:00 AM
#10
No problem. Glad to help.
I learned more too.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width