Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB Script to add site to Java Exception List 4 53
Problem to open text file 11 73
Allow User To Arrange Columns At Datagridview 3 19
Exit the loop 4 37
I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

896 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

17 Experts available now in Live!

Get 1:1 Help Now