G
Greg Maxey
I am really not very good at working with fonts, character codes, and
symbols in VBA and need some help.
I have been playing around with a UserForm macro that will replicate
UserForm option button selections in the document. The UserForm
displays 7 frames containing 5 optionbuttons each. The document
displays a seven questions with 5 WingDings2 Symbol 154 (a small
unfilled circle). All 35 symbols are bookmarked with a name
corresponding to the groups and optionbuttons in the UserForm. When
the user makes their selection in the UserForm and the command button
click event in the the UserForm is executed, corresponding the symbols
in the document are changed WindDings2 Symbol 158 (a small circle with
a filled center).
I used the macro recorder to get a start on how to insert the
appropriate symbol at the bookmark using VBA.
The result is:
Selection.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3942, _
Unicode:=True
Normally when I write to a bookmark and need to preserve the bookmark
I use:
Dim oRng as Word.Range
Set oRng = ActiveDocument.Bookmarks("Groupa1").Range
oRng.Text = "My desired text here"
ActiveDocument.Bookmarks.Add "Groupa1", oRng
Using .InsertSymbol as shown above the only way I have been able to
achieve the same result is:
Set oRng = ActiveDocument.Bookmarks("Groupa1").Range
oRng.Delete
oRng.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3938, _
Unicode:=True
oRng.MoveEnd wdCharacter, 1
ActiveDocument.Bookmarks.Add "Groupa1", oRng
Note: CharacterNumber:=-3938 inserts the filled circle symbol.
Question: Is there a way I can use "Range.Text = ????" to do this
job? I often see code containing lines like ChrW$(####) that
represents text or symbol. Is there something like that that will
represent the WindDing2 symbols I need?
Thanks.
P.S.
Here is my complete Command_Button code:
Private Sub CommandButton1_Click()
Dim catArray() As String
Dim lngGroup As Long
Dim bSelection As Boolean
Dim i As Long
Dim acontrol As Control
Dim resultsArray(6) As Long 'One less than number of groups
Dim oRng As Word.Range
catArray = Split("a|b|c|d|e|f|g", "|")
'Loop throug each group. Note: controls are indexed starting with 0
Application.ScreenUpdating = False
For lngGroup = 0 To 6
bSelection = False
'Loop through each frame control
For i = 0 To 4
Set acontrol = Controls("Frame" & catArray(lngGroup)).Controls(i)
Set oRng = ActiveDocument.Bookmarks("Group" & catArray(lngGroup) &
i + 1).Range
oRng.Delete
oRng.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3942, _
Unicode:=True
oRng.MoveEnd wdCharacter, 1
ActiveDocument.Bookmarks.Add "Group" & catArray(lngGroup) & i + 1,
oRng
If acontrol.Value = True Then
resultsArray(lngGroup) = i + 1
bSelection = True
Set oRng = ActiveDocument.Bookmarks("Group" & catArray(lngGroup)
& i + 1).Range
oRng.Delete
oRng.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3938, _
Unicode:=True
oRng.MoveEnd wdCharacter, 1
ActiveDocument.Bookmarks.Add "Group" & catArray(lngGroup) & i +
1, oRng
End If
Next i
If Not bSelection Then
MsgBox "No selection was made for Group " & lngGroup + 1
Exit Sub
End If
Next lngGroup
lngGroup = 0
For i = 0 To UBound(resultsArray)
lngGroup = lngGroup + resultsArray(i)
Next i
MsgBox Format(Val(lngGroup) / 7, "#.00")
Unload Me
Application.ScreenUpdating = True
Application.ScreenRefresh
End Sub
symbols in VBA and need some help.
I have been playing around with a UserForm macro that will replicate
UserForm option button selections in the document. The UserForm
displays 7 frames containing 5 optionbuttons each. The document
displays a seven questions with 5 WingDings2 Symbol 154 (a small
unfilled circle). All 35 symbols are bookmarked with a name
corresponding to the groups and optionbuttons in the UserForm. When
the user makes their selection in the UserForm and the command button
click event in the the UserForm is executed, corresponding the symbols
in the document are changed WindDings2 Symbol 158 (a small circle with
a filled center).
I used the macro recorder to get a start on how to insert the
appropriate symbol at the bookmark using VBA.
The result is:
Selection.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3942, _
Unicode:=True
Normally when I write to a bookmark and need to preserve the bookmark
I use:
Dim oRng as Word.Range
Set oRng = ActiveDocument.Bookmarks("Groupa1").Range
oRng.Text = "My desired text here"
ActiveDocument.Bookmarks.Add "Groupa1", oRng
Using .InsertSymbol as shown above the only way I have been able to
achieve the same result is:
Set oRng = ActiveDocument.Bookmarks("Groupa1").Range
oRng.Delete
oRng.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3938, _
Unicode:=True
oRng.MoveEnd wdCharacter, 1
ActiveDocument.Bookmarks.Add "Groupa1", oRng
Note: CharacterNumber:=-3938 inserts the filled circle symbol.
Question: Is there a way I can use "Range.Text = ????" to do this
job? I often see code containing lines like ChrW$(####) that
represents text or symbol. Is there something like that that will
represent the WindDing2 symbols I need?
Thanks.
P.S.
Here is my complete Command_Button code:
Private Sub CommandButton1_Click()
Dim catArray() As String
Dim lngGroup As Long
Dim bSelection As Boolean
Dim i As Long
Dim acontrol As Control
Dim resultsArray(6) As Long 'One less than number of groups
Dim oRng As Word.Range
catArray = Split("a|b|c|d|e|f|g", "|")
'Loop throug each group. Note: controls are indexed starting with 0
Application.ScreenUpdating = False
For lngGroup = 0 To 6
bSelection = False
'Loop through each frame control
For i = 0 To 4
Set acontrol = Controls("Frame" & catArray(lngGroup)).Controls(i)
Set oRng = ActiveDocument.Bookmarks("Group" & catArray(lngGroup) &
i + 1).Range
oRng.Delete
oRng.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3942, _
Unicode:=True
oRng.MoveEnd wdCharacter, 1
ActiveDocument.Bookmarks.Add "Group" & catArray(lngGroup) & i + 1,
oRng
If acontrol.Value = True Then
resultsArray(lngGroup) = i + 1
bSelection = True
Set oRng = ActiveDocument.Bookmarks("Group" & catArray(lngGroup)
& i + 1).Range
oRng.Delete
oRng.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3938, _
Unicode:=True
oRng.MoveEnd wdCharacter, 1
ActiveDocument.Bookmarks.Add "Group" & catArray(lngGroup) & i +
1, oRng
End If
Next i
If Not bSelection Then
MsgBox "No selection was made for Group " & lngGroup + 1
Exit Sub
End If
Next lngGroup
lngGroup = 0
For i = 0 To UBound(resultsArray)
lngGroup = lngGroup + resultsArray(i)
Next i
MsgBox Format(Val(lngGroup) / 7, "#.00")
Unload Me
Application.ScreenUpdating = True
Application.ScreenRefresh
End Sub