#1
|
|||
|
|||
Extracting text from Start and End position
I know how to extract text in MS Word Content between 2 words using `.Find`
I am trying to extract text (with all formatting) between 2 positions. For example 10 and 200. If I use MID then I lose formatting. One thought process is 1. Delete text from position 1 till 2 2. Delete text from position 201 till end of document This is where I am stuck. If the logic is correct then how do I delete the relevant text? |
#2
|
||||
|
||||
Simple - have your macro:
1. Mark all content as hidden. 2. Find the text you want to preserve and unhide it 3. Find and delete all hidden text.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
The formatting of the last paragraph in the range requires the paragraph mark to be included since that is where the paragraph formatting is held. But you could also just apply the last paragraph formatting to the pasted area after the copy has happened.
The property you should be using is .FormattedText Do a search for this term on this forum to see examples which duplicate ranges with formatting.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#4
|
|||
|
|||
Quote:
Quote:
For example, let's say I have this simple text Quote:
Code:
MyString = "The quick brown fox jumps over the lazy dog" Debug.Print Mid(MyString, 11, 31 - 11) |
#5
|
|||
|
|||
Quote:
|
#6
|
||||
|
||||
Which is exactly what the process I described will achieve. Read point 3.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
My Apologies. I was editing my reply. As I mentioned in my previous post
Quote:
Thanks again for patiently helping me out Paul. |
#8
|
||||
|
||||
For example:
Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument With .Range .Font.Hidden = True With .Find .ClearFormatting .Replacement.ClearFormatting .Format = False .Forward = True .Wrap = wdFindContinue .MatchWildcards = True .Text = "Section 1.10.32*voluptatem.^13" .Replacement.Text = "^&" .Replacement.Font.Hidden = False .Execute Replace:=wdReplaceAll .Replacement.ClearFormatting .Font.Hidden = True .Format = True .Text = "*" .Replacement.Text = "" .Execute Replace:=wdReplaceAll End With End With End With Application.ScreenUpdating = True End Sub Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
The starting position & the end position (which is a number) is fed by another macro.
|
#10
|
||||
|
||||
In which case:
Code:
Sub Demo(StartPos As Long, EndPos As Long) With ActiveDocument .Range(StartPos, EndPos).Cut .Range.Paste End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
PURRRRFECT!
Thanks a ton Paul. Code:
.Range(StartPos, EndPos).Cut |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Choose multiple start and end position of window in a row... | Ganesh Kumar | Excel | 9 | 04-01-2019 08:26 AM |
Help with Formula to extracting text from text string | Haha88 | Excel | 7 | 01-13-2019 01:33 AM |
Help with Formula to extracting text from text string | Haha88 | Excel | 9 | 02-05-2018 01:04 AM |
Start from the previous position | Dimsok | Word VBA | 7 | 09-14-2014 06:07 AM |
Justify Paragraph Start position with VBA | jeff_kaufman | Word VBA | 2 | 11-09-2013 12:15 PM |