Results 1 to 8 of 8
  1. #1
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts

    How to place check box followed by text

    My target is to place a checkbox, followed by text, followed by drop down menu.
    I can make the check box to appear, but the text is not shown. Perhaps because the "cursor" is still located in the check box pbject.
    Here is the code:
    Code:
        Dim ImprObj As ContentControl
        Set ImprObj = ActiveDocument.ContentControls.Add(wdContentControlCheckBox)
        
        With Selection
        .EndKey Unit:=wdLine
        .Font.ColorIndex = wdBlack
        .Font.Bold = True
        .Font.Underline = False
        .Font.Size = 12
        .MoveRight
        .MoveRight
        .TypeText ""My Text" & vbTab
    
        End With

    Any Idea?

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    You need to learn to work with Range objects, besides which, if this is for your template, why are you still trying to do it via code?

    Furthermore, all this hard-formatting you're using is a violation of Word's basic design. Formatting should be controlled through Style definitions.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts
    I am creating a template, as you suggested, but I really prefer to create it with macro.
    The end user will get the result of the macro run, not the macro itself.

    This is how I maintain your guide lines: deliver template and not .docm, and I keep the great flexibility of the template creation by code.
    Now I can change easily the form, all programmable.
    The form includes about 15 drop down menus with medical complicated words, and about 10 lines with check boxes.
    I really don't want to draw the form by hand.

    I am not sure what style means, I guess I need to learn this also, but this will have to wait due to time limits.

    BTW, I solved the above problem by using
    Code:
    .EndKey Unit:=wdLine
    .

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    You are wasting time creating a template with a macro. The whole point of using a template is so neither you nor your users need to use code for something that is better done manually. All this code you're trying to use to create it will, in theory at least, only ever be used once - you can then throw it away because everything from then on will use the template, not the code you're trying to use to create it.

    You would do far better learning to use Styles properly and creating the template manually. Failing to implement Styles properly is more of a hindrance to your users than a benefit.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by macropod View Post
    You are wasting time creating a template with a macro. The whole point of using a template is so neither you nor your users need to use code for something that is better done manually. All this code you're trying to use to create it will, in theory at least, only ever be used once - you can then throw it away because everything from then on will use the template, not the code you're trying to use to create it.
    I don't know (yet) enough about STYLE to answer, so I assume you point is valid.
    But this template is not going to be "one time job". for sure.

    I am helping a friend with his clinic to improve his manual editing process, and this is the 3rd time he is changing his spec. I can understand that: once he learned the capabilities, he knows what more can he ask for. So this is going to be a dynamic process for a some time, but I have the infrastructure: I can now change content, syntax, entries in drop downs so easily.

    I also use this mini project for learning VBA. So once I release the first working template (I still need to implement "auto start", working dirs, PDF creation etc.), I will invest effort on learnign style and how to use it correctly.

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by YigalB View Post
    But this template is not going to be "one time job". for sure.
    \It seems you still don't understand what templates are. You create a template once. From then on, any new documents of that kind simply retrieve all their layuout from the template. They have no need of any code you might use to create the template. Leaving it there just adds bloat.
    I am helping a friend with his clinic to improve his manual editing process, and this is the 3rd time he is changing his spec.
    All the more reason to create a document with the required layout, using the GUI (not code), then save it as a template.
    So once I release the first working template (I still need to implement "auto start", working dirs, PDF creation etc.), I will invest effort on learnign style and how to use it correctly.
    That is going about it the wrong way around.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #7
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by macropod View Post
    \It seems you still don't understand what templates are. You create a template once. From then on, any new documents of that kind simply retrieve all their layuout from the template. They have no need of any code you might use to create the template. Leaving it there just adds bloat.
    I think I do. My point is that I will have template A running for 2-3 months. one time generated. Then the user will ask: "can you add another drop box?". So I will generate template B, once, which will be used for few more months. So each template is generated once, but several templates will be generated. Each has a small modification. The code will allow me flexibility.

    Quote Originally Posted by macropod View Post
    All the more reason to create a document with the required layout, using the GUI (not code), then save it as a template.
    I disagree. Code is easily to read and maintain, easier to code and change, and even faster once base is created. Also it easier to duplicate structures (sub routines, functions) and create dependencies. And, perhaps the most critical issue: easier to document. How do you place comments on GUI?

    Quote Originally Posted by macropod View Post
    That is going about it the wrong way around.

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by YigalB View Post
    My point is that I will have template A running for 2-3 months. one time generated. Then the user will ask: "can you add another drop box?". So I will generate template B, once, which will be used for few more months. So each template is generated once, but several templates will be generated. Each has a small modification.
    You've just proved my point.
    I disagree. Code is easily to read and maintain, easier to code and change, and even faster once base is created. Also it easier to duplicate structures (sub routines, functions) and create dependencies. And, perhaps the most critical issue: easier to document.
    Really? So why do you suppose you're having so many issues? The fact you're working with Selections all the time is a clear indication you haven't even taken the time to learn how to code properly using Word VBA.
    How do you place comments on GUI?
    With the GUI you don't need to comment everything because you're not having to explain what you'd be using code to - it's already perfectly obvious if a given content control, for example, is in column 3, row 2 of the 3rd table in Section 4.

    I'm done wasting time on this. You seem determined to do things the worst way possible and I'm not going to invest my time in helping you to not do things properly.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •