Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Somewhere Over the Rainbow
    Posts
    232
    Thanks
    0
    Thanked 1 Time in 1 Post
    Consider the following as an example word document:

    The cow says moo, the cat says meow, and I say hello.

    I would like to include a button into that document that would select or highlight a set region of text.
    In other words if I set the region to highlight from the word "cow" to the word "cat". Then by clicking
    on the button it would highlight that range of text for me.

    Thanks,
    Andrew
    Time can fix anything.....even a broken clock. - Handy Andy

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by HandyAndy View Post
    I would like to include a button into that document that would select or highlight a set region of text.
    In other words if I set the region to highlight from the word "cow" to the word "cat". Then by clicking
    on the button it would highlight that range of text for me.
    By highlight, do you mean the kind applied with the highlighter button on the toolbar/ribbon?

    Do users need to be able to edit the file? In other words, it couldn't be locked as a Word form?

    I think you can use the button in the Control Toolbox even if the document is not locked, however, I can't recall whether I have tried that.

    Let's assume the button will work. Now you need some code. If you have marked the section you want to highlight with a bookmark, then it should not be difficult to apply formatting to the range marked by the bookmark. If there is no bookmark and you need to do some kind of search to identify that passage, it gets more complicated.

  3. #3
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Somewhere Over the Rainbow
    Posts
    232
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks for the fast reply,
    when I say highlight I mean when you click and drag over any given text.
    For example to copy and past text.
    Yes, the text would also have to be editable.
    I don't know if that would make things difficult, but the text that would get highlighted won't stay the same.
    Therefore if I were to define a range to be selected, I would have to specify it other than using the words "cow" to "cat"
    If it makes things easier, consider this:
    I have a 2 page word document, on the first page there is a click able button.
    The whole document with the exception of the button must be editable.
    The button would act as a "select all", but only for the second page.

    I hope I explained it better, or made it any easier to accomplish.
    Time can fix anything.....even a broken clock. - Handy Andy

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by HandyAndy View Post
    when I say highlight I mean when you click and drag over any given text.
    Let's use the term select for that. I VBA, you can select a range of text in the document.

    Quote Originally Posted by HandyAndy View Post
    I have a 2 page word document, on the first page there is a click able button.
    The whole document with the exception of the button must be editable.
    The button would act as a "select all", but only for the second page.
    If the button is the first thing and you want to select everything after it, that is possible. But what is the point? The user can use Ctrl+A or Edit>Select All to do this.

  5. #5
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Somewhere Over the Rainbow
    Posts
    232
    Thanks
    0
    Thanked 1 Time in 1 Post
    I understand you could just press CTRL+A, which is great is you want to select the whole document.
    Frequently I copy only a portion of the word file after I make some changes to it.
    Kind of like using it as a template.
    How do I make that button that you mentioned? The one that selects everything below it?
    Could I make it select everything above it instead?
    Thanks very much.
    Time can fix anything.....even a broken clock. - Handy Andy

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by HandyAndy View Post
    How do I make that button that you mentioned? The one that selects everything below it?
    Could I make it select everything above it instead?
    I actually had to learn a lot of new things to make this little demo, and suddenly it's after midnight. Well, hope it's helpful.

    To modify the buttons, display the Control Toolbox and click the upper left icon to enter design mode. When finished, exit design mode to make the buttons operable.

    To modify the code, open the "ThisDocument" module.

    [attachment=87240:SelectBeforeOrAfter.doc]
    Attached Files Attached Files

  7. #7
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Somewhere Over the Rainbow
    Posts
    232
    Thanks
    0
    Thanked 1 Time in 1 Post
    You are awesome! Thanks so much.
    I haven't had a chance to configure the buttons yet, but it works well playing with it.

    PS: I like the Abe speech too.
    Time can fix anything.....even a broken clock. - Handy Andy

  8. #8
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Somewhere Over the Rainbow
    Posts
    232
    Thanks
    0
    Thanked 1 Time in 1 Post
    Okay, there is only one problem.
    The document that I need to use the button on has some form fields.
    In order for the button to work correctly it needs to be unprotected, and
    in order for the form to work it needs to be protected.

    Also, I am sorry for saying "Highlights". I should have said Selects.
    Is it possible to edit a threads title? probably not.....
    Time can fix anything.....even a broken clock. - Handy Andy

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Quote Originally Posted by HandyAndy View Post
    In order for the button to work correctly it needs to be unprotected, and
    in order for the form to work it needs to be protected.
    You can add this line at the beginning of the macro:

    ActiveDocument.Unprotect

    If you have set a password, change this to

    ActiveDocument.Unprotect Password:="topsecret"

    At the end of the macro, add a line

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

    If you want to set the password again, change it to

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="topsecret"

    Quote Originally Posted by HandyAndy View Post
    Also, I am sorry for saying "Highlights". I should have said Selects.
    Is it possible to edit a threads title? probably not.....
    You can edit the subject of this thread by editing the first post. See Can I fix it?

  10. #10
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Somewhere Over the Rainbow
    Posts
    232
    Thanks
    0
    Thanked 1 Time in 1 Post
    I am embarrassed to say that I don't know where the beginning and the end of the macro is.
    I know how to open and edit it, but that is as far as my understanding with macros is.
    I tried placing the code at the very end and the very beginning, but I got an error so I assume it has to be within a certain tag.
    I should get my self a good book on this subject.
    Also for my understanding.....Is a macro just a place to store VB scripting?
    At least I was able to fix the subject of this thread.
    I was always more of a hands on hardware guy, and not so much into coding.
    Thanks,
    Andrew
    Time can fix anything.....even a broken clock. - Handy Andy

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    A macro is a single piece of code that begins with

    Sub macroname()

    and ends with

    End Sub

    Macros and other code are stored in containers named modules.

    [attachment=87245:x.png]
    Attached Images Attached Images
    • File Type: png x.png (6.1 KB, 0 views)

  12. #12
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Somewhere Over the Rainbow
    Posts
    232
    Thanks
    0
    Thanked 1 Time in 1 Post
    Cool, thanks.
    Time can fix anything.....even a broken clock. - Handy Andy

  13. #13
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Somewhere Over the Rainbow
    Posts
    232
    Thanks
    0
    Thanked 1 Time in 1 Post
    I still can't seem to get it to work.
    I didn't have a macro for the document, so I created one with a module and placed the code in as you said.
    I am a little confused now because I thought that if I had a button and form fields, that I would have to have a macro.

    Please see the attached word document.

    Thanks again
    Attached Files Attached Files
    Time can fix anything.....even a broken clock. - Handy Andy

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The code that Jefferson wrote is in the ThisDocument module (under Microsoft Word Objects). It doesn't help to create a new macro and add just those two lines to it.

    But in the document that you attached, the button and code are useless. It would only make sense to select text in an unprotected section of the document.

  15. #15
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Somewhere Over the Rainbow
    Posts
    232
    Thanks
    0
    Thanked 1 Time in 1 Post
    I know it doesn't make sense, but can it be done?
    Time can fix anything.....even a broken clock. - Handy Andy

Page 1 of 2 12 LastLast

Posting Permissions

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