#1
|
|||
|
|||
Using Find & Replace in Word instead of GREP Function in Adobe Indesign
Hello,
I have an XML file for my exported mobile messages, for example Code:
<sms address="????" time="Jul 8, 2020 8:55:20 AM" date="1594187720118" type="1" body="My message" read="1" service_center="???" name="Ruyan" /> In other words, I want the content of these parameters (SMS address, Time, Body, Name) without quotation marks, each in a new line, but in the same paragraph, in this order: Body Time Name SMS address Thanks |
#2
|
||||
|
||||
Assuming your don't want to deal with xml-based code and the attribute order is always consistent, you could use something like this to extract the content
Code:
Sub Macro1() Dim sText As String, arrText() As String, i As Integer, sOutput As String sText = ActiveDocument.Paragraphs(1).Range.Text arrText = Split(sText, """") ' For i = LBound(arrText) To UBound(arrText) ' Debug.Print i, arrText(i) ' Next i sOutput = arrText(9) & vbLf & arrText(3) & vbLf & arrText(15) & vbLf & arrText(1) Debug.Print sOutput End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Quote:
Secondly, dear Andrew, after running your macro, no changes happen. Thirdly, the numbers inside parenthesis in your code, what represent?: Code:
sOutput = arrText(9) & vbLf & arrText(3) & vbLf & arrText(15) & vbLf & arrText(1) Lastly, do you want to attach a demo file? |
#4
|
||||
|
||||
If you want a demo file you should create it and post it here. Then I can make the macro work according to what you actually have rather than what I think you might have. I presume you don't want code for a single input line but that is all you have provided.
The code I posted assumes the text you posted in https://www.msofficeforums.com/163102-post1.html is the first paragraph of a Word document. The code takes just this one paragraph's text as the input and converts it into an array with a new item every time the string contains a ". Then it grabs the text from the positions in that array that align with your required data values. These array positions are the numbers you see in the sOutput line. In my code, the output appears in your vba Immediate Window. If you want to do something else with it then you need to explain what exactly that is. The three disabled lines in the code (the lines with the ' at the start of the line) output each of the array positions to the Immediate Window so you can work out what numbers align with the data you require.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
[QUOTE=Guessed;163125][/QUOTE]
Quote:
Excuse me, I don't understand this feature, because all messages in the XML file are copied to a Word file, in order to run a VBA code on it, to extract what I want. Thank you again for your consideration |
#6
|
||||
|
||||
If your document follows the same pattern as the demo you attached, this code will convert its contents.
Code:
Sub Macro1() Dim sText As String, arrText() As String, i As Long, aRng As Range With ActiveDocument For i = .Paragraphs.Count To 1 Step -1 Set aRng = .Paragraphs(i).Range sText = aRng.Text arrText = Split(sText, """") If UBound(arrText) > 14 Then aRng.Text = arrText(9) & Chr(11) & arrText(3) & Chr(11) & arrText(15) & Chr(11) & arrText(1) & vbCr End If Next i End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
Quote:
Wow, it's wonderful and amazing Again, thank you thank you Last edited by Jakov93; 10-15-2021 at 04:12 AM. |
#8
|
|||
|
|||
Dear Andrew,
after working with my data, it appears that messages are reversely sorted(newest to oldest) which is not a suitable choice and requires reading from bottom to top. However, I faced the same problem mentioned in this post: https://www.msofficeforums.com/word/...tml#post163131 But after googling, the sorting depends on the application that used for exporting messages for example, Super Backup Pro, makes XML and sort messages from newest to oldest. SMS Backup & Restore, make XML and sort messages from oldest to newest (best choice). So according to (SMS Backup & Restore), the pattern was changed to this: Code:
<sms protocol=”0″ address=”+111111111111″ date=”1615582579995″ type=”1″ subject=”null” body=”my message……” toa=”null” sc_toa=”null” service_center=”+111111111111″ read=”1″ status=”-1″ locked=”0″ date_sent=”1615582589000″ readable_date=”Mar 12, 2021 11:56:19 PM” contact_name=”Ruyan” /> body readable_date type See attached file. Last edited by Jakov93; 10-15-2021 at 11:40 AM. |
#9
|
||||
|
||||
Jakov93
The point of forums like this is to educate people to help themselves. You have all the code you need to do this yourself. Put both the first and second macros into a document and enable the disabled lines in the first one and pay careful attention to what the macro does. It will help you work out what you need to change to get the second macro to work with your new xml attribute pattern.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#10
|
|||
|
|||
I am so sorry dear Andrew for annoying
I appreciate your continuous help Thank you again |
Tags |
find & replace, find replace;wildcards, word vba |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Some text are missing while importing into Adobe InDesign | Muthukumaran | Word | 2 | 07-23-2019 11:30 PM |
Function in a Macro used to Find & Replace | koehlerc14 | Word VBA | 3 | 02-15-2019 11:59 AM |
Find and Replace function shooting off screen to the left of the document | Mattblack | Word | 1 | 04-10-2014 03:06 PM |
Indesign Table to MS word for Editing | Kathy Neal | Word Tables | 1 | 01-15-2013 07:56 AM |
Bad view when using Find and Find & Replace - Word places found string on top line | paulkaye | Word | 4 | 12-06-2011 11:05 PM |