![]() |
|
#1
|
||||
|
||||
![]()
Regardless of whether you want to "want to play with text and not the rtf as opened in word", that doesn't mean you can't open the file as text in Word and process it as such. For example:
Code:
Sub Demo() Dim wdDoc As Document Set wdDoc = Documents.Open(FileName:="C:\Users\rahul\Desktop\PLR\1.rtf, Format:=wdOpenFormatText, AddToRecentFiles:=False) With wdDoc 'process here .Close SaveChanges:=True End With End Sub Code:
Sub EditRTFFile() 'Requires a reference to Microsoft VBScript Regular Expressions 5.5 Dim DataFile As String, TextLine As String, Data As String, regEx DataFile = "C:\Users\rahul\Desktop\PLR\1.rtf" Set regEx = CreateObject("vbScript.RegExp") Data = "" Open DataFile For Input As #1 Do Until EOF(1) Line Input #1, TextLine On Error Resume Next With regEx_ .Global = True .MultiLine = True .IgnoreCase = True .Pattern = "\{\\\w{4}\\\w{4}\\\w{11}" TextLine = regEx_.Replace(TextLine, "mmrk$&") End With Data = Data & TextLine & vbCrLf Loop Close #1 Open DataFile For Output As #1 Print #1, Data Close #1 Set regEx = Nothing End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
||||
|
||||
![]()
Problem is not in opening file, reading it line by line and doing regex. Real problem starts after that.
For example I am getting by any means, StrTxt as string which contains multiple lines or I don't know how string behaves inside object. As far as my problem concerns I get StrTxt from two souces. 1. by opening a file. 2. from httprequests. In both the case I end up with StrTxt as string. So the question is, If My StrTxt contains multiple occurrences of a string like "string", how to get all of it. For example in hypothetical string. Code:
StrTxt = "mmrkxyz" & vbCr & "mmrkyzx" & vbCr & "xyz" & vbCr & "yzx" & vbCr & "mmarkxxx" Code:
StrTxt = "mmrkxyz" & vbCr & "mmrkyzx" & vbCr & "mmarkxxx" To make it simple, My strings contains multiple lines. I just want it to reduced to lines that contains specific characteristics like Left(StrTxt, 4) = "mmrk". |
#3
|
||||
|
||||
![]() Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
||||
|
||||
![]()
That Is what I am currently doing sir. Have no problem with That but thought if withing VBA it is possible It would be great for knowledge.
|
![]() |
Tags |
vbscript, word vba |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
wardw | Word | 7 | 05-07-2018 09:13 AM |
![]() |
Amitti | Word VBA | 2 | 04-10-2017 07:35 PM |
![]() |
TechEd | Word VBA | 5 | 07-05-2014 08:12 PM |
![]() |
omahadivision | Excel Programming | 12 | 11-23-2013 12:10 PM |
![]() |
paulkaye | Word | 4 | 12-06-2011 11:05 PM |