Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-14-2021, 03:24 AM
Jakov93 Jakov93 is offline Using Find & Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find & Replace in Word instead of GREP Function in Adobe Indesign Office 2010
Novice
Using Find & Replace in Word instead of GREP Function in Adobe Indesign
 
Join Date: Jul 2021
Posts: 17
Jakov93 is on a distinguished road
Post 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" />
However, I want to create a book for these messages in chat style by using Adobe InDesign, but I found some difficulty while dealing with GREP.

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
Reply With Quote
  #2  
Old 10-14-2021, 04:25 PM
Guessed's Avatar
Guessed Guessed is offline Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,946
Guessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud of
Default

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
Reply With Quote
  #3  
Old 10-14-2021, 07:20 PM
Jakov93 Jakov93 is offline Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Office 2010
Novice
Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign
 
Join Date: Jul 2021
Posts: 17
Jakov93 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
Firstly, thank you for your reply
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)
because I want to add additional attributes such as "Type".
Lastly, do you want to attach a demo file?
Reply With Quote
  #4  
Old 10-14-2021, 09:49 PM
Guessed's Avatar
Guessed Guessed is offline Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,946
Guessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud of
Default

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
Reply With Quote
  #5  
Old 10-14-2021, 10:19 PM
Jakov93 Jakov93 is offline Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Office 2010
Novice
Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign
 
Join Date: Jul 2021
Posts: 17
Jakov93 is on a distinguished road
Default [QUOTE=Guessed;163125][/QUOTE]

Quote:
Originally Posted by Guessed View Post
I presume you don't want code for a single input line but that is all you have provided.
You are right completely, because I have more than 4000 messages, and I posted just an example, see attached file.

Quote:
Originally Posted by Guessed View Post
In my code, the output appears in your vba Immediate Window.
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
Attached Files
File Type: docx demo.docx (16.9 KB, 3 views)
Reply With Quote
  #6  
Old 10-14-2021, 10:41 PM
Guessed's Avatar
Guessed Guessed is offline Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,946
Guessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud of
Default

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
Reply With Quote
  #7  
Old 10-14-2021, 11:19 PM
Jakov93 Jakov93 is offline Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Office 2010
Novice
Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign
 
Join Date: Jul 2021
Posts: 17
Jakov93 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
If your document follows the same pattern as the demo you attached
Yes, it follows the same pattern

Quote:
Originally Posted by Guessed View Post
this code will convert its contents.
Wow, it's wonderful and amazing
Again, thank you thank you

Last edited by Jakov93; 10-15-2021 at 04:12 AM.
Reply With Quote
  #8  
Old 10-15-2021, 03:26 AM
Jakov93 Jakov93 is offline Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Office 2010
Novice
Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign
 
Join Date: Jul 2021
Posts: 17
Jakov93 is on a distinguished road
Default

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” />
So please edit your code to extract these contents only:
body
readable_date
type

See attached file.
Attached Files
File Type: docx demo2.docx (16.9 KB, 3 views)

Last edited by Jakov93; 10-15-2021 at 11:40 AM.
Reply With Quote
  #9  
Old 10-15-2021, 08:54 PM
Guessed's Avatar
Guessed Guessed is offline Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,946
Guessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud of
Default

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
Reply With Quote
  #10  
Old 10-15-2021, 10:56 PM
Jakov93 Jakov93 is offline Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Windows 10 Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Office 2010
Novice
Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign
 
Join Date: Jul 2021
Posts: 17
Jakov93 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Jakov93
You have all the code you need to do this yourself.
I am so sorry dear Andrew for annoying
I appreciate your continuous help
Thank you again
Reply With Quote
Reply

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
Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Function in a Macro used to Find & Replace koehlerc14 Word VBA 3 02-15-2019 11:59 AM
Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign 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
Using Find &amp; Replace in Word instead of GREP Function in Adobe Indesign Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2022 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft