?
Solved

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

Posted on 2014-01-01
3
Medium Priority
?
1,142 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 1332 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 1332 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 668 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

Technology Partners: 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

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

752 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