Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 03-11-2019, 03:20 AM
ganesang ganesang is offline Windows XP Office 2016
Competent Performer
 
Join Date: Jul 2018
Posts: 125
ganesang is on a distinguished road
Default Need macro for XML tagging in word doc

Hi Paul,

I need your help on this....

I have the documents with styles which needs to be XML tagging based on the styles available in the document.



for ex.,

If paragraph styled as "para", then should be tagged that paragraph, <para></para>.

So, the xml tagging needs to be add what style is available in the document and what para or list items.

Please refer the sample and let me know.
Attached Files
File Type: docx XML - tagging.docx (15.5 KB, 3 views)
Reply With Quote
  #2  
Old 03-12-2019, 03:19 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,098
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

A trivial challenge:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Para As Paragraph
For Each Para In ActiveDocument.Paragraphs
  With Para.Range
    .Characters.First.InsertBefore "<" & .Style & ">"
    .Characters.Last.InsertBefore "</" & .Style & ">"
  End With
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 03-12-2019, 07:37 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,080
Guessed has a spectacular aura aboutGuessed has a spectacular aura aboutGuessed has a spectacular aura about
Default

Not so trivial if the style name is not a valid xml element name. For instance you can't have a space in the name so "Heading 1" will need to become "Heading1". If your styles include potentially problematic characters like &* or begin with a number or underscore then you might also run in to problems.

You might need to include a function to ensure only xml valid names get in the tags.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 03-12-2019, 09:44 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,098
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

I have to wonder, though, whether the OP is trying to produce true XML code...
The output my code produces is consistent with the sample document's contents.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 03-13-2019, 02:39 AM
ganesang ganesang is offline Windows XP Office 2016
Competent Performer
 
Join Date: Jul 2018
Posts: 125
ganesang is on a distinguished road
Default

Hi Paul

Thanks for providing the code.

Yes. The tagging is not a valid XML code but i can change that code using find and replace in other xml editors.

thanks
Ganesan. G
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to transfer data from Word to another Word document with bookmark Jovan Yong Word VBA 3 04-17-2018 04:27 AM
Macro to put 1 word of a MS Word file in 1 cell of a Word or Excel Table Singh_Edm Word VBA 6 11-13-2015 08:48 PM
Macro Question: Need help making a macro to highlight the first word in every sentence LadyAna Word 1 12-06-2014 10:39 PM
Word 2003 Macro problem running in Word 2010 norwood Word VBA 2 02-03-2014 06:49 PM
Macro for tagging and rearranging selected text for revision caotico Word VBA 0 03-28-2012 06:35 PM


All times are GMT -7. The time now is 04:10 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft