Solved

Word 2010 - VBA - Cutting a string of text up to the TAB character

Posted on 2014-01-01
3
1,124 Views
Last Modified: 2014-01-06
I have a string of text that ends with a TAB character and would like to select and cut this string of text.  (without the tab character!)
My cursor is at the beginning of the line
What is the VBA code to do this?
0
Comment
Question by:brothertruffle880
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 333 total points
ID: 39749698
Personally I'd use split i.e.

split(activedocument.Paragraphs(1).Range.Text, vbtab)(0)

Open in new window


Chris
0
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 333 total points
ID: 39749702
Within the stated scenario then this could be as easy as:

Sub splitPara()
Dim rng As Range
Dim str As String

    Set rng = Selection.Paragraphs(1).Range
    str = Split(rng.Text, vbTab)(0)
    MsgBox str
End Sub

Open in new window


Chris
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 167 total points
ID: 39749722
If you actually want to do a Cut operation on the paragraph, you could do it like this
Sub CutToTab()
    Dim rng As Range

    Set rng = Selection.Range
    rng.MoveEndUntil vbTab
    rng.MoveEnd wdCharacter, 1
    rng.Cut
End Sub

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question