Solved

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

Posted on 2014-01-01
3
1,051 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
  • 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
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…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now