Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-17-2014, 03:11 AM
KKChris KKChris is offline Russian ComboBox Value Windows 8 Russian ComboBox Value Office 2010 32bit
Novice
Russian ComboBox Value
 
Join Date: Feb 2014
Posts: 2
KKChris is on a distinguished road
Default Russian ComboBox Value

Hi Forum,
I need your help.
I have got a ComboBox with 2 entries “conforms” and “not tested” and die Values are Russian words. The goal is to select the words in English and get the Russian words as output.

Code at the moment:
Code:
  PrivateSubDocument_ContentControlOnExit(ByValContentControl AsContentControl, Cancel AsBoolean)
      Dimrng AsRange
      Dimbm AsBookmark
      Dimbmt AsBookmark
  
  
      If(ContentControl.Type = wdContentControlComboBox) Then
          Setrng = ContentControl.Range
          Setbm = rng.Bookmarks(1)
          Setbmt = ActiveDocument.Bookmarks(bm & "tgt")
  
  
      ElseIf(ContentControl.Type = wdContentControlText) Then
  
      EndIf
  
  EndSub




Bmt stands for the Combobox/Textfield – Textmark.
Now I got 2 problems.
On the one hand, I believe that I have to solve that problem by using a second ComboBox, cause I can’t work with Russian letters in VBA. On the other hand: How can I get the Indexchoice from the first ComboBox in a second one? Look at the image for more information.


Reply With Quote
  #2  
Old 02-17-2014, 09:16 AM
gmaxey gmaxey is offline Russian ComboBox Value Windows 7 32bit Russian ComboBox Value Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

If I select the first choice .. Test2 should automatically choose the same.

As you've probably seen, there is no built-in change event for content controls so "automatically" is really not possible. You have to select the first choice then "exit."

There are several ways to work around this. But, why does the 2nd CC need to be a dropdown? If you select the second choice in test 1, all you really want is for Test2 to display "COOT" Correct?

One method is to map the first CC to a CustomXMLPart and then use one of the built-in CustomXMLPart events:

Here is how:

In a new blank document. Add a standard code module and paste in this code:

Code:
Option Explicit
Sub AddCCsAndMap()
Dim oCC As ContentControl
Dim oRng As Word.Range
With ActiveDocument
  .Range.Text = "Select English Term: "
  Set oRng = .Range
  oRng.Collapse wdCollapseEnd
  Set oCC = .ContentControls.Add(Type:=wdContentControlDropdownList, Range:=oRng) '.Range) 'Selection.Range)
  With oCC
    .Title = "Master"
    With .DropdownListEntries
      .Add "Chose an item.", "Nothing selected."
      .Add "A"
      .Add "B"
    End With
  End With
  oRng.Start = .Range.End - 1
  oRng.InsertBefore vbCr
  oRng.Start = .Range.End - 1
  oRng.Text = "Russian Equivalent: "
  oRng.Start = .Range.End - 1
  Set oCC = .ContentControls.Add(wdContentControlText, oRng)
  With oCC
    .Title = "Slave"
    .LockContents = True
    .SetPlaceholderText , , "Nothing chosen."
  End With
  .Range.InsertAfter vbCr + vbCr & "There is an apparent ""bug"" or at least a design flaw in the NodeAfterReplace event." & vbCr _
                     & "If the Content Control XML mapping node value is null (i.e., Content control displaying normal Placeholder text) the event is not triggered when" _
                     & " the null value is replaced with a non-null value (i.e., a Content Control item is selected).  Additionally the event is not triggered" _
                     & " when a non-null value is replaced with a null value.  The event is only triggered when a non-null value is replaced with another non-null value." & vbCr & vbCr _
                     & "The work around is to use and store a non-null value in the XML node that mimics placeholder text.  CC.Range" _
                     & " formatting attributes are used to make the imposter text appear as placeholder text in the content control."
End With
MapCCs
AutoOpen
End Sub
Sub MapCCs()
Dim oCC As ContentControl
Dim strXML As String
Dim oCustXMLPart As CustomXMLPart
  strXML = "<?xml version='1.0' encoding='utf-8'?><Root><Master> </Master></Root>"
  ClearXMLParts
  Set oCustXMLPart = ActiveDocument.CustomXMLParts.Add(strXML)
  Set oCC = ActiveDocument.SelectContentControlsByTitle("Master").Item(1)
  oCC.XMLMapping.SetMapping "/Root/Master[1]"
  
  Set oCustXMLPart = Nothing
  AutoOpen
  oCC.DropdownListEntries(2).Select
  oCC.DropdownListEntries(1).Select
  Set oCC = Nothing
End Sub
Sub AutoOpen()
  ThisDocument.InitializeMonitor
End Sub
 Sub ClearXMLParts()
Dim i As Long
For i = ActiveDocument.CustomXMLParts.Count To 4 Step -1
  ActiveDocument.CustomXMLParts(i).Delete
Next i
End Sub
Then in the ThisDocument module of the document, paste the following code:

Code:
Option Explicit
Dim WithEvents oMonitor As CustomXMLPart
Sub InitializeMonitor()
  On Error Resume Next
  Set oMonitor = ThisDocument.CustomXMLParts(4)
End Sub
Private Sub oMonitor_NodeAfterReplace(ByVal OldNode As Office.CustomXMLNode, ByVal NewNode As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
Select Case NewNode.ParentNode.BaseName
  Case "Master"
    ActiveDocument.SelectContentControlsByTitle("Master").Item(1).Range.Font.Color = wdColorAutomatic
    ActiveDocument.SelectContentControlsByTitle("Slave").Item(1).LockContents = False
    Select Case oMonitor.SelectSingleNode("/Root/Master[1]").Text
      Case "Nothing selected."
        ActiveDocument.SelectContentControlsByTitle("Master").Item(1).Range.Font.Color = wdColorGray45
        With ActiveDocument.ContentControls(2).Range
          .Text = "Nothing chosen."
          .Font.Color = wdColorGray45
        End With
      Case "A"
        With ActiveDocument.ContentControls(2).Range
          .Text = "Your ""A"" Russian term here."
          .Font.Color = wdColorGreen
        End With
      Case "B"
        With ActiveDocument.ContentControls(2).Range
          .Text = "Your ""B"" Russian term here."
          .Font.Color = wdColorBlue
        End With
   End Select
   ActiveDocument.SelectContentControlsByTitle("Slave").Item(1).LockContents = True
End Select
End Sub
Now open the standard module and execute the procedure named:
AddCCsAndMap
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 02-18-2014, 01:09 AM
KKChris KKChris is offline Russian ComboBox Value Windows 8 Russian ComboBox Value Office 2010 32bit
Novice
Russian ComboBox Value
 
Join Date: Feb 2014
Posts: 2
KKChris is on a distinguished road
Default

Thanks for your fast answer. Your solution looks nice, but the problem is, that i can't use russian letters in my VBA Makro. Therefore I can't display the whole word correctly.
Reply With Quote
  #4  
Old 02-18-2014, 09:01 AM
gmaxey gmaxey is offline Russian ComboBox Value Windows 7 32bit Russian ComboBox Value Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

You might replace:
.Text = "Your ""A"" Russian term here."

With a function to go out and get that text from a table cell in a reference word document, or a spreadsheet.

e.g.,
.Text = oRefDoc.Tables(1).Cell(1,3).Range.Text
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 02-18-2014, 09:49 AM
NobodysPerfect NobodysPerfect is offline Russian ComboBox Value Windows 7 64bit Russian ComboBox Value Office 2010 32bit
Competent Performer
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default

As I always try not to use linked documents, I use my quick workaround for short terms:

Type the needed term in Word, select it and then call the following function.

Code:
Function GetUnicodeString(Optional UniCode As String) As String
Dim oData As New DataObject         'Link to Microsoft Forms 2.0 Object Library 
Dim i%
    
    If UniCode = "" Then UniCode = Selection
        For i = 1 To Len(UniCode)
            GetUnicodeString = GetUnicodeString & "ChrW(" & (AscW(Mid(UniCode, i, i))) & ") & "
        Next
        GetUnicodeString = Left(GetUnicodeString, Len(GetUnicodeString) - 3)
        
    With oData
        .SetText GetUnicodeString
        .PutInClipboard
    End With
    
    MsgBox "String in clipboard for use in VBA ...   ", vbOKOnly + vbInformation, "In Clipboard"

End Function
The "GetUnicodeString" function returns the corresponding ChrW()%ChrW()& ... string which can be pasted directly into the VBA code.

Only suitable for short strings in Userforms or ListBoxes, etc.

NP
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
combobox issue Deepa Shrestha Word 0 07-29-2013 09:47 PM
Typing in Russian shekala Outlook 0 11-12-2012 05:57 PM
ComboBox ListIndex = -1 even though it does NOT = -1 Joe Patrick Word VBA 0 08-03-2011 08:34 AM
Russian ComboBox Value Code to export value from ComboBox ilkks Word VBA 7 05-25-2011 04:06 AM
Russian ComboBox Value Combobox manipulation vsempoux Word VBA 3 10-31-2009 08:58 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft