Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #15  
Old 06-09-2015, 08:26 PM
macropod's Avatar
macropod macropod is offline VBA to save word user form value to xml Windows 7 64bit VBA to save word user form value to xml Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Another approach would be to write your metadata directly from the userform to a text file with an xml extension, using code along the lines of:
Code:
Dim StrXML As String, StrName As String
StrXML = "<metadata>" & vbCrLf
StrXML = StrXML & "<SystemInfo>" & Customer_Info.Text & "</SystemInfo>" & vbCrLf
StrXML = StrXML & vbTab & "<NumberOfRecords>" & Record_Count.Text & "</NumberOfRecords>" & vbCrLf
StrXML = StrXML & vbTab & vbTab & "<FileTransferHeader>" & vbCrLf
StrXML = StrXML & vbTab & vbTab & "<ProcessingDate>" & Format(Date, "YYYYMMDD") & "</ProcessingDate>" & vbCrLf
StrXML = StrXML & vbTab & vbTab & "<ProcessingTime>" & Format(Date, "hhmmss") & "</ProcessingTime>" & vbCrLf
StrXML = StrXML & vbTab & vbTab & "<FileName>" & ActiveDocument.Name & "</FileName>" & vbCrLf
StrXML = StrXML & vbTab & "</FileTransferHeader>" & vbCrLf & vbTab & "<RecordsInfo>" & vbCrLf
StrXML = StrXML & vbTab & vbTab & "<Name>" & Name.Text & "</Name>" & vbCrLf
StrXML = StrXML & vbTab & vbTab & "<Address>" & Address.Text & "</Address>" & vbCrLf
StrXML = StrXML & vbTab & vbTab & "<Author>" & ActiveDocument.BuiltInDocumentProperties(wdPropertyAuthor) & "</Author>" & vbCrLf
StrXML = StrXML & vbTab & "</RecordsInfo>" & vbCrLf & "</metadata>"
StrName = Split(ActiveDocument.FullName, ".")(0) & ".xml"
Open StrName For Output As #1
Print #1, StrXML
Close #1
The above code snippet assumes your userform has textboxes named:
Customer_Info
Record_Count
Name
Address
and that the document has been saved. The xml file is given the same name as the document it is obtained from and is saved to the same folder.

Although the text file is formatted with tabs so its structure resembles what you see when you view the xml in I.E., that isn't really necessary.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
User Form - Close Paragraphs SonyaEnz Word VBA 4 06-05-2015 06:16 AM
User form abdulgani Excel 0 12-15-2014 05:54 AM
how to save contents in textbox in VB2013 form into a Word document? saltlakebuffalo Word VBA 6 12-10-2014 06:12 PM
VBA to save word user form value to xml Force User to Save As lgillespie Word 6 09-09-2013 03:13 PM
VBA to save word user form value to xml User Form placasse47 Excel Programming 3 08-01-2012 05:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:05 PM.


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