Help on Macro and Drop Down Boxes

D

Dawn

Here is the code I am trying to get work, can anyone help me? My
objective is the following:
From the nine options in the dropdown box I would like only the last
item to run a macro. The macro is taking only part of a table (trying
to use bookmarks.) It will only take a hand full of cells, merge them,
delete the contents that was already there, and then add a text form
field with 50 characters. This is all to be done in a protected form in
MS Word 2003. I can get bits and pieces working but not the whole
thing as a whole. Please help me. My code is below. FYI: I am a
beginner in the visual basic.

Public Sub DropDown_Click()

With ActiveDocument.FormFields("DropDown1")
Select Case ActiveDocument.FormFields("DropDown1").Result
Case 0
'no selection, do nothing
Case 1
'no selection, do nothing
Case 2
'no selection, do nothing
Case 3
'no selection, do nothing
Case 4
'no selection, do nothing
Case 5
'no selection, do nothing
Case 6
'no selection, do nothing
Case 7
'no selection, do nothing
Case 8
'#8 Blind
Call MacroOne
End Select
End With
End Sub
=================================================
Sub MacroOne()

Selection.GoTo What:=wdGoToBookmark, Name:="LeftSide"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.Cells.Merge
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Range.Cells(1).VerticalAlignment =
wdCellAlignVerticalCenter
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = "Text1"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
With .TextInput
.EditType Type:=wdRegularText, Default:="", Format:=""
.Width = 50
End With
End With
End Sub
 
D

Doug Robbins - Word MVP

For a start, you will need to unprotect the document to do anything with the
bookmark. If there is only one circumstance under which action is to be
taken, then it is simpler to just use and If...Then...End If construction.

I would use the following, assuming that 8 is the item in the drop down list
that is selected:

If ActiveDocument.FormFields("DropDown1").result = "8" Then
ActiveDocument.Unprotect
ActiveDocument.Bookmarks("LeftSide").Range.Text = ""
ActiveDocument.Bookmarks("LeftSide").Range.Select
With Selection
.Cells.Merge
.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.FormFields.Add Range:=.Range, Type:=wdFieldFormTextInput
.PreviousField.Select
With Selection.FormFields(1)
.Name = "Text1"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
With .TextInput
.EditType Type:=wdRegularText, Default:="", Format:=""
.Width = 50
End With
End With
End With
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset
End If

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top