Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2015, 07:11 AM
Rose roon Rose roon is offline VBA to save word user form value to xml Windows 7 64bit VBA to save word user form value to xml Office 2007
Novice
VBA to save word user form value to xml
 
Join Date: Jun 2015
Posts: 28
Rose roon is on a distinguished road
Default VBA to save word user form value to xml


Hi,

I am new to VBA.
I have a userform in word and need to save that value as xml document.
Appreciate your help.

Thanks & Regards,
Rose
Reply With Quote
  #2  
Old 06-07-2015, 12:34 PM
ally3 ally3 is offline VBA to save word user form value to xml Windows XP VBA to save word user form value to xml Office 2007
Novice
 
Join Date: Jun 2015
Posts: 1
ally3 is on a distinguished road
Default

How did you manage to save the VDA into a document?
Reply With Quote
  #3  
Old 06-08-2015, 03:49 AM
Rose roon Rose roon is offline VBA to save word user form value to xml Windows 7 64bit VBA to save word user form value to xml Office 2007
Novice
VBA to save word user form value to xml
 
Join Date: Jun 2015
Posts: 28
Rose roon is on a distinguished road
Default

Hi,

Thank you.
Yes first need to add the form value to document attribute, then export to xml.
Any suggesstions?

Appreciate your help

Thanks & Regards
Rose
Reply With Quote
  #4  
Old 06-08-2015, 04:53 AM
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: 21,963
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

What, exactly are you trying to save as xml - the userform or some data? AFAIK, you can't save an Office userform as an xml object and saving the data from a userform in an xml format requires you to supply all the relevant xml tags - whose attributes depend on what you're trying to do with the xml.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-08-2015, 07:47 AM
Rose roon Rose roon is offline VBA to save word user form value to xml Windows 7 64bit VBA to save word user form value to xml Office 2007
Novice
VBA to save word user form value to xml
 
Join Date: Jun 2015
Posts: 28
Rose roon is on a distinguished road
Default

Hi Paul,

Macro using VBA which is embedded as part of a Microsoft Word template
and to be used by users to capture predefined metadata as part of the document.
This Macro will capture the metadata as a user input form.
The Metadata is saved as an XML file and the word document is saved as “.DOC” file extension.

Hope it clear

Thanks & Regards,
Rose
Reply With Quote
  #6  
Old 06-08-2015, 07:56 AM
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: 21,963
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

OK, so you want to save the 'metadata' the user inputs into the userform. In that case, as per my previous post:
Quote:
saving the data from a userform in an xml format requires you to supply all the relevant xml tags - whose attributes depend on what you're trying to do with the xml
That, after all, is all that xml code is - plain text with the appropriate xml tags. Furthermore, xml code doesn't have a format, per se. What you see in xml viewers like I.E. is just the way they've been programmed to display xml code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 06-08-2015, 08:11 PM
Rose roon Rose roon is offline VBA to save word user form value to xml Windows 7 64bit VBA to save word user form value to xml Office 2007
Novice
VBA to save word user form value to xml
 
Join Date: Jun 2015
Posts: 28
Rose roon is on a distinguished road
Default save data as word doc metadata

Hi,

I have a word template and in that I have user form fields like Name, Address etc. once user entered the data need to save that data in word file meta data. please help how to go ahead.

Appreciate your help

Regards,
Rose
Reply With Quote
  #8  
Old 06-08-2015, 08:12 PM
Rose roon Rose roon is offline VBA to save word user form value to xml Windows 7 64bit VBA to save word user form value to xml Office 2007
Novice
VBA to save word user form value to xml
 
Join Date: Jun 2015
Posts: 28
Rose roon is on a distinguished road
Default

Hi Paul,

Thank you

Regards,
Rose
Reply With Quote
  #9  
Old 06-08-2015, 08:27 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: 21,963
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

Hi Rose,

Please clarify your intentions - do you want to save these items as part of the document properties (e.g. Author/Client/Department or new custom properties - see under File|Properties|Advanced Properties>Custom), as content in the body of the document, or as something else?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 06-08-2015, 08:54 PM
Rose roon Rose roon is offline VBA to save word user form value to xml Windows 7 64bit VBA to save word user form value to xml Office 2007
Novice
VBA to save word user form value to xml
 
Join Date: Jun 2015
Posts: 28
Rose roon is on a distinguished road
Default

Hi Paul,

Thanks, want to save us document properties

Regards,
Rose
Reply With Quote
  #11  
Old 06-08-2015, 10:44 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: 21,963
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

You can create & update any custom document properties you might require with code like:
Code:
Dim StrClient As String, StrAddr As String
StrClient = "Client Name": StrAddr = "Client Address"
With ActiveDocument
  With .CustomDocumentProperties
    On Error Resume Next
    .Add Name:="Client Name", Type:=msoPropertyTypeString, LinkToContent:=False, Value:=StrClient
    .Item("Client Name").Value = StrClient
    .Add Name:="Client Address", Type:=msoPropertyTypeString, LinkToContent:=False, Value:=StrAddr
    .Item("Client Address").Value = StrAddr
  End With
End With
Simply replace "Client Name" and "Client Address" in the above code with references to the appropriate textboxes on your userform.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 06-08-2015, 11:31 PM
Rose roon Rose roon is offline VBA to save word user form value to xml Windows 7 64bit VBA to save word user form value to xml Office 2007
Novice
VBA to save word user form value to xml
 
Join Date: Jun 2015
Posts: 28
Rose roon is on a distinguished road
Default

Hi Paul,

Thanks you so much.
sorry for asking many questions how to export this Client Name and Client Address value to xml. I have asked to do like this- please advice


<matadata>
<SystemInfo>Customer Info</SystemInfo>
<NumberOfRecords>2</NumberOfRecords>
<FileTransferHeader>
<ProcessingDate>20150531</ProcessingDate>
<ProcessingTime>205036</ProcessingTime>
<FileName>sample.docx</FileName>
</FileTransferHeader>
<RecordsInfo>

<Name>Rose</Name>
<Address>20150531</Address>
<Author>Admin</Author>
</RecordsInfo>
</matadata>

Regards,
Rose
Reply With Quote
  #13  
Old 06-09-2015, 12:03 AM
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: 21,963
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

That is rather different from simply adding them to the document's properties, though having done so you will find the corresponding xml code inside the docx file. As I said in your other thread ():
Quote:
saving the data from a userform in an xml format requires you to supply all the relevant xml tags - whose attributes depend on what you're trying to do with the xml
How you would go about that depends on whether you already have some boilerplate xml code like:

<metadata>
<SystemInfo>Customer Info</SystemInfo>
<NumberOfRecords>2</NumberOfRecords>
<FileTransferHeader>
<ProcessingDate>20150531</ProcessingDate>
<ProcessingTime>205036</ProcessingTime>
<FileName>sample.docx</FileName>
</FileTransferHeader>
</metadata>

or:

<metadata>
<SystemInfo>Customer Info</SystemInfo>
<NumberOfRecords>2</NumberOfRecords>
<FileTransferHeader>
<ProcessingDate>20150531</ProcessingDate>
<ProcessingTime>205036</ProcessingTime>
<FileName>sample.docx</FileName>
</FileTransferHeader>
<RecordsInfo>
<Name></Name>
<Address></Address>
<Author></Author>
</RecordsInfo>
</metadata>

In the first example, you'd need to add all of:

<RecordsInfo>
<Name>Rose</Name>
<Address>20150531</Address>
<Author>Admin</Author>
</RecordsInfo>

to the file, perhaps replacing </metadata> as well. In the second example, you might just want to insert:
Rose
into:
<Name></Name>
and so on - or you might want to replace the entire:

<RecordsInfo>
<Name></Name>
<Address></Address>
<Author></Author>
</RecordsInfo>
</metadata>

block with:

<Name>Rose</Name>
<Address>20150531</Address>
<Author>Admin</Author>
</RecordsInfo>
</metadata>

So, you see, it's all a matter of deciding which approach works best for you. There are no hard & fast rules about this.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 06-09-2015, 12:45 AM
Rose roon Rose roon is offline VBA to save word user form value to xml Windows 7 64bit VBA to save word user form value to xml Office 2007
Novice
VBA to save word user form value to xml
 
Join Date: Jun 2015
Posts: 28
Rose roon is on a distinguished road
Default

Hi Paul,

Thank you
On a button click event need to save only this data as xml in given location.
first step need to add metadata in word document .
second step save as xml not whole document only the mentioned one.


Name and Address value will take from property got from user form.
Author,date,time,filename(sample.doc),etc from the document

<matadata>
<SystemInfo>Customer Info</SystemInfo>
<NumberOfRecords>2</NumberOfRecords>
<FileTransferHeader>
<ProcessingDate>20150531</ProcessingDate>
<ProcessingTime>205036</ProcessingTime>
<FileName>sample.docx</FileName>
</FileTransferHeader>
<RecordsInfo>
<Name>Rose</Name>
<Address>20150531</Address>
<Author>Admin</Author>
</RecordsInfo>
</matadata>

Thank you for your help.

Regards,
Rose
Reply With Quote
  #15  
Old 06-09-2015, 03:57 AM
gmaxey gmaxey is online now VBA to save word user form value to xml Windows 7 32bit VBA to save word user form value to xml Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Rose,
I'm pressed for time today, but one option would be to use mapped content controls to store your metadata. Mapped CCs are bound to a data node in a customXMLPart that become part of the document. It is an easy step to then save the data as a text file:

Sub ScratchMacro()
Dim fso As Object
'A basic Word macro coded by Greg Maxey
'MsgBox ActiveDocument.CustomXMLParts(4).XML
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile("C:\New File")
oFile.WriteLine ActiveDocument.CustomXMLParts(1).XML
oFile.Close
Set fso = Nothing
Set oFile = Nothing
lbl_Exit:
Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



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 04:10 AM.


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