none
Loading Arabic data from an external text file into a ComboBox using VBA RRS feed

  • Question

  • Hi,
    I've Created a ComboBox in Word 2007 that loads some Arabic text from an external text file.
    It works but the problem is when i want to print it, it just breaks the words and creates a whole messed up page.

    I've tested three methods so far and all of them have the same bug.
    Seems that the problem is with the language and encoding. I tried everything that i could to fix it but the result is still the same.

    has any of you tested that before ?
    I can send the files or write the codes if it helps ?

    thanks in advance
    Thursday, December 2, 2010 8:13 AM

Answers

  • Hi Lord Sepid

    <<Let me explain it this way, I entered your code into my form, the form has a content control combobox named TestCombo.

    The only thing that happens is that when I move the cursor to TestCombo by keyboard (by pressing tab or arrow keys) it just shows the list for less than a half second and then the list disappears. You have to press alt+Down arrow again to see the list.

    -Is it really what it's suppose to do or there's something wrong here ?>>

    I don't see that. If I click into the combobox or use the keyboard (other than Tab) to move into it, the list is displayed. I don't see the list at all if I TAB (which I believe I mentioned) I'm using 2007 SP2...

    FWIW, SendKeys basically mimics the user typing on the keyboard. For this reason it tends to be unpredictable and unreliable. I never use or suggest it if there's any other way. It's possible that something on your system is conflicting sending these "key presses". From the description, something is "pressing Escape" or doing some other kind of action.

    <<-Is it possible that when I press Enter for example, it shows the list ?

    (I mean replacing the "alt+Down arrow" with "Enter")>>

    I doubt it. Alt+Down arrow is built into Word. Trying to do something using the Enter key would probably be even less reliable than the macro executing when moving into the field.

    =============

    About the only other thing that occurs to me would mean you'd have to move beyond VBA. VSTO (VIsual Studio Tools for Office) would let you work with .NET Framework Windows forms controls on the surface of the document. But compared to VBA, things can get rather complicated. So I think it becomes a question of just how badly you want this on the document surface...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Monday, December 13, 2010 11:12 AM
    Thursday, December 9, 2010 11:04 AM
    Moderator

All replies

  • Is it the topic that no one's interested in or there's really no answer for that ?

    I tested it in Word 2010 and the result ws the same.

    Please if someone knows something just give me a hint.

    thanks

    Saturday, December 4, 2010 6:42 AM
  • > Is it the topic that no one's interested

    I can't speak for anyone else here, but it's not because such problems are uninteresting - for my part, it's because I know how difficult and time-consuming they can be to investigate, particularly for those of us who do not normally work in a RTL script or multi-script environment. For the volunteers here, that can mean a longer investment in time and effort than people really want to make.

    I see you have also posted in the Answers forum and have had a response, but I would give Andreas a bit more time. You are welcome to send your files etc. to me as well at

    pjj at pjjnet dot demon dot co dot uk

    I suggest that  we continue in the Answers forum rather than here.



    Peter Jamieson
    Saturday, December 4, 2010 8:19 AM
  • Thanks for the reply.

    I didn't know where this subject belongs so I posted it everywhere that i thought could be related in any way.

    Also "Andreas" told me that he couldn't help me so i didn't want to disturb him with more questions.

    But i tried everything that i could think of like testing in Word 2010, setting new fonts and encodings, testing every method that i could find to load a text file into a combobox and every little thing that came to my mind.

    And now i'm just waiting for some answers from the forums.

    I'll send you the test-files. But i still think that there's something wrong with VB that comes in between and corrupts everything.

    Is there another way to load an external file into a combobox without using VB ?

    Saturday, December 4, 2010 8:43 AM
  • Hi Lord Sepid

    You don't mention what kind of control this ComboBox is, but I'm guessing it's MSForms 2.0?

    I vaguely recollect discussions around this kind of thing in the context of working with the controls on a UserForm. I'm sure it was in the old word.vba.general newsgroup and years ago. What it boiled down to, if memory serves, was "you can't do that". If the control isn't being displayed by the language environment you want to use (an Arabic UI in this case) it can't display the characters.

    On re-reading your question, however, it appears the combobox is able to display the text correctly? The problem only occurs when you print? So maybe this is a content control?

    So, what happens if you insert some of this text directly into the document range? Does it also not print correctly? Have you tried formatting the text (paragraph) expllicitly with the language you need to use?

    What's the language of the rest of the document?


    Cindy Meister, VSTO/Word MVP
    Saturday, December 4, 2010 10:41 AM
    Moderator
  • Hi Cindy

    > You don't mention what kind of control this ComboBox is...

    It's a "Combo Box ActiveX control", and it's not in a UserForm.

    > what happens if you insert some of this text directly into the document range?

    The document's language is Arabic and works fine with the Arabic contents, even when i create a "combo box content control" and populate it with Arabic data it works OK but just the activex control causes this problem.

    In fact "Office Word" itself has no problem with supporting Arabic language, It seems that when vba comes in between it creates a mess with the document.

    Do you have any solution for that or any other suggestion that could give the same result ?

    I can send you the test-files if you have time to test them ?

    Saturday, December 4, 2010 12:44 PM
  • I've sent you an email, but for the sake of the others here, 

     a. it's in the design mode and the print mode that it goes wrong

     b. a simple experiment here suggests that

        - the problem is that with the Arabic script, Word normally selects the correct presentation forms for "joined-up" writing, but in this case Word, or perhaps the ActiveX control, sometimes reverts to using the "standard" form that you actually typed.

        - a possible solution might be to enter the Unicode codes for the presentation forms directly. I have no idea how difficult that might be or whether it just results in other problems, but that's as far as I can get right now.


    Peter Jamieson
    Saturday, December 4, 2010 3:28 PM
  • I saw your email first and i replied to it.

    > I have no idea how difficult that might be or whether it just results in other problems, but that's as far as I can get right now.

    Thanks anyway, you are a real helper. (My English is not so good so excuse me if i used the word "helper" wrong!)

    ;)

    Saturday, December 4, 2010 4:02 PM
  • > a possible solution might be to enter the Unicode codes for the presentation
     
    This conversation is split over several forums and is hard to follow! ActiveX is not Unicode-aware so that, unfortunately, doesn't really work (and, anyway, I'm not sure it would solve anything - see my comments in Technet).
     

    Enjoy,
    Tony
    www.WordArticles.com
    Saturday, December 4, 2010 5:49 PM
  • Yes, it's a shame about the forums.

    But the unicode presentation forms approach does in fact, appear to get somewhere. Whether it is enough for "a solution" I think we'll have to wait and see.

    And I agree that an approach based on content controls would be preferable from a "future-proofing" view (among others) - the OP had his reasons for heading for the ActiveX approach, but I haven't explored those reasons at all. 

     


    Peter Jamieson
    Saturday, December 4, 2010 6:30 PM
  • As I have just suggested in the Technet Forum, if an autotext item displays/prints correctly, then perhaps an autotextlist field could be used in place of the combobox.

    -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Peter Jamieson" wrote in message news:46745c0d-a478-4a5c-879c-1b30c0e41f60@communitybridge.codeplex.com...

    Yes, it's a shame about the forums.

    But the unicode presentation forms approach does in fact, appear to get somewhere. Whether it is enough for "a solution" I think we'll have to wait and see.

    And I agree that an approach based on content controls would be preferable from a "future-proofing" view (among others) - the OP had his reasons for heading for the ActiveX approach, but I haven't explored those reasons at all.

    -- Peter Jamieson


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Saturday, December 4, 2010 8:54 PM
  • Hi Cindy

    > You don't mention what kind of control this ComboBox is...

    It's a "Combo Box ActiveX control", and it's not in a UserForm.

    > what happens if you insert some of this text directly into the document range?

    The document's language is Arabic and works fine with the Arabic contents, even when i create a "combo box content control" and populate it with Arabic data it works OK but just the activex control causes this problem.

    In fact "Office Word" itself has no problem with supporting Arabic language, It seems that when vba comes in between it creates a mess with the document.

    Do you have any solution for that or any other suggestion that could give the same result ?


    Just to add my "vote" to other suggestions that apparently have been made elsewhere: I'd definitely look at using a content control rather than an MSForms ActiveX control. ActiveX controls are not optimized to function on the document surface and are comparatively old technology. I have grave doubts that you'll ever be able to print correctly using the ActiveX control.

    If, as Peter says, you do have reasons for wanting to use an ActiveX control, I'd consider replacing the ActiveX control with a content control, or even plain text, during the printing process. After printing is complete, re-instate the ActiveX control. Or, maintain a second "shadow" document where there are no ActiveX controls and print that.


    Cindy Meister, VSTO/Word MVP
    Sunday, December 5, 2010 8:00 AM
    Moderator
  • BTW, I realised that using the presentation forms is likely to break the facility to select an entry in the dropdown list by typing on the keyboard. Even if the control can display the text correctly, I doubt if it will look for anything other than the code entered on the keyboard.
    Peter Jamieson
    Sunday, December 5, 2010 8:02 AM
  • Hi Guys

    I was really surprised when i first saw these comments here !

    I didn't expect anyone to answer me back about this problem. But apparently I was wrong. thanks anyway

    > This conversation is split over several forums and is hard to follow!

    As I wrote in the parallel forum (!?), I think it's better to continue this subject in here.

    > the OP had his reasons for heading for the ActiveX approach, but I haven't explored those reasons at all.

    These are the reasons I wrote to peter for moving from Content Controls to ActiveX Controls :

    ---------------
    The ComboBox content control works fine and i've created the first version of my form using that type.
    But i wanted to have two options for the combo box and it wasn't possible with this type (at least with my information, if you know otherwise let me know)
    first : i wanted it to work like a real combo box, you know, like when you type the first letter it goes directly to the items that start with that letter.(the list is sorted alphabetically)
    second : i wanted to write some codes for it in vba like populating it from an external file,but apparently there's no way i can do that for this type of combo boxes.
    ---------------
    Now I'm gonna test Doug's and Cindy's ideas and I think it's gonna take me for a few hours before any conclusion.
    But I'll check in here occasionally.

    thank you all
    Sunday, December 5, 2010 10:59 AM
  • > perhaps an autotextlist field could be used in place of the combobox

    I tested your method Doug and autotextlist worked correctly. But the problem is the number of my items in every comboBox can vary between 300 to 1000 and that's not a good idea for an autotextlist because finding an specific item in that kind of list would need a lot more time and enegy than a ComboBox. Besides the reason I migrated to ActiveX was to be able to populate the combobox from an external file, So that when someone else wants to add something to the list he wouldn't be needing to edit the main file that might cause some disfunctionality in the document. In my few searches nothing was mentioned as populating an autotextlist from an external file. I may find it through a little more search but I'm not sure if it fits with my expectations.

    I'll wait to hear your opinion about this Doug (or other members who have something to add to this)

    > Cindy : I'd consider replacing the ActiveX control with a content control, or even plain text, during the printing process ...

    Cindy, can you give me a hint on how should I replace an ActiveX ComboBox with something else during the printing process?

    Sunday, December 5, 2010 3:32 PM
  • Alright, I just succeeded to populate a combobox content control with the content of an external text file.

    That is the second reason I migrated to ActiveX controls.

    If one of you can just tell me how can I accomplish the first reason that I mentioned in the post before the previous post, I'll never go back to ActiveX controls, ever, I promise !

    I'm gonna go home to sleep now and I'd be very happy if you surprise me in the morning ;)

    thanks

    good night

    Sunday, December 5, 2010 7:13 PM
  • Hi Lord Sepid

    <<If one of you can just tell me how can I accomplish the first reason that I mentioned in the post before the previous post>>

    Mmm, only partially. If the list is dropped down, then typing the letter will jump in the list.

    alt+down arrow will display the list

    As long as the user doesn't TAB to go into the content control, the following macro (that must be in the document's ThisDocument module) will drop down the list:

    Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
      Select Case ContentControl.Title
        Case "TestCombo"
          DoEvents
          SendKeys "%{Down}", False
        Case Else
      End Select
    End Sub
    
    

    Cindy Meister, VSTO/Word MVP
    Monday, December 6, 2010 10:41 AM
    Moderator
  • Hi Cindy

    Yesterday I accidentally found the alt+down thing while I was playing with the Content Control ComboBoxes.

    But the additional codes can really be useful.

    Just a small problem, when the focus goes on the specific content control it just flashes and goes back to normal. Is it possible that it stays on the list or by pressing the Down button (without Alt) it drops the list down?

     

    Tuesday, December 7, 2010 11:49 AM
  • Yesterday I accidentally found the alt+down thing while I was playing with the Content Control ComboBoxes.

    But the additional codes can really be useful.

    Just a small problem, when the focus goes on the specific content control it just flashes and goes back to normal. Is it possible that it stays on the list or by pressing the Down button (without Alt) it drops the list down?

    I'm sorry, but I'm not following what you want to say in the last paragraph - it's not clear under what cirucmstances what, exactly, is happening and whether the macro code is involved.

    Cindy Meister, VSTO/Word MVP
    Tuesday, December 7, 2010 5:25 PM
    Moderator
  • Cindy, I'm wrapping up my form based on your advice on sticking with the content controls.

    I give you credit for not understanding what I said because now that I read it myself I don't get it either ;)

    Let me explain it this way, I entered your code into my form, the form has a content control combobox named TestCombo.

    The only thing that happens is that when I move the cursor to TestCombo by keyboard (by pressing tab or arrow keys) it just shows the list for less than a half second and then the list disappears. You have to press alt+Down arrow again to see the list.

    -Is it really what it's suppose to do or there's something wrong here ?

    -Is it possible that when I press Enter for example, it shows the list ?

    (I mean replacing the "alt+Down arrow" with "Enter")

    Wednesday, December 8, 2010 8:17 AM
  • Hi Lord Sepid

    <<Let me explain it this way, I entered your code into my form, the form has a content control combobox named TestCombo.

    The only thing that happens is that when I move the cursor to TestCombo by keyboard (by pressing tab or arrow keys) it just shows the list for less than a half second and then the list disappears. You have to press alt+Down arrow again to see the list.

    -Is it really what it's suppose to do or there's something wrong here ?>>

    I don't see that. If I click into the combobox or use the keyboard (other than Tab) to move into it, the list is displayed. I don't see the list at all if I TAB (which I believe I mentioned) I'm using 2007 SP2...

    FWIW, SendKeys basically mimics the user typing on the keyboard. For this reason it tends to be unpredictable and unreliable. I never use or suggest it if there's any other way. It's possible that something on your system is conflicting sending these "key presses". From the description, something is "pressing Escape" or doing some other kind of action.

    <<-Is it possible that when I press Enter for example, it shows the list ?

    (I mean replacing the "alt+Down arrow" with "Enter")>>

    I doubt it. Alt+Down arrow is built into Word. Trying to do something using the Enter key would probably be even less reliable than the macro executing when moving into the field.

    =============

    About the only other thing that occurs to me would mean you'd have to move beyond VBA. VSTO (VIsual Studio Tools for Office) would let you work with .NET Framework Windows forms controls on the surface of the document. But compared to VBA, things can get rather complicated. So I think it becomes a question of just how badly you want this on the document surface...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Monday, December 13, 2010 11:12 AM
    Thursday, December 9, 2010 11:04 AM
    Moderator