Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Jul 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Command to select Word2000 text to a strText var?

    Anyone know the VBA command I should look up to select typed characters from a VBA-opened Word2000 file to turn these characters into a strText value? I've looked up and had no luck with SelRTF and SelText.

    Once VBA brings up a file I have VBA move the cursor to >>>, and then I can get it to block select the 12 characters to the right of that >>>, but I can't get the 12 characters to convert into a Variable capable of guiding further processing.

    Thanks for any direction you can pass along!

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command to select Word2000 text to a strText var?

    Sammy,

    That's pretty clever with the 12 ^?s. Good thing they don't need the next 500 characters, eh?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Command to select Word2000 text to a strText var?

    What method are you currently using to block out the 12 characters?

    Sam's suggestion is one (clever) method for doing this, but there are others. In any case finding the 12 characters is the hard part; assigning them to a string variable is the easy part (strSelChars = Selection.Text)

    Also, is this just plain text in a document, or is this text entered in a textbox in a userform?

  4. #4
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Command to select Word2000 text to a strText var?

    That's why I used the end property in the other solution. --Sam <img src=/S/bow.gif border=0 alt=bow width=15 height=15>
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Command to select Word2000 text to a strText var?

    The short answer is that you need to use the .Text property, but I noticed that you mentioned selection. You probably want to use a range instead, so that you don't move the insertion point. See below for sample code using first a range object and then the Selection object. Hope this helps! Let me know if you have more problems. --Sam

    Sam Barrett, MTL Systems, Inc., mailto:sam@mtl.com
    Brainbench MVP, <A target="_blank" HREF=http://www.brainbench.com>http://www.brainbench.com</A>

    And the things that you have heard...commit these to faithful
    men who will be able to teach others also. 2 Timothy 2:2
    <pre>Sub Macro1()
    Dim rngText As Range
    Dim strText As String
    Set rngText = ActiveDocument.Range ' rngText is the entire document
    With rngText.Find
    .ClearFormatting ' Clear previous find
    .Text = ">>>"
    .Execute ' rngText is now the >>>
    End With
    rngText.Collapse wdCollapseEnd ' collapse the range to the end of the >>>
    rngText.End = rngText.End + 12 ' get the twelve characters
    strText = rngText.Text ' return them as text
    MsgBox strText ' here they are!
    End Sub

    Sub Macro2()
    Dim strText As String
    Selection.StartOf wdStory, wdMove
    With Selection.Find
    .ClearFormatting
    .Text = ">>>^?^?^?^?^?^?^?^?^?^?^?^?"
    .Execute
    End With
    Selection.Start = Selection.Start + 3
    strText = Selection.Text
    MsgBox strText
    End Sub
    </pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  6. #6
    New Lounger
    Join Date
    Jul 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command to select Word2000 text to a strText var?

    All three methods of selecting string variables would work better than the work-around I eventually applied. I used strFilename = ActiveDocument.BuiltInDocumentProperties(wdPropert ySubject) and used the name of the next days filename as my subject before using strFilename to insert file that next days table.

    Works, but nowhere near as elegant as your suggestion or those posted by Sammy.

    Thanks again to you both!

Posting Permissions

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