#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
How did you manage to save the VDA into a document?
|
#3
|
|||
|
|||
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 |
#4
|
||||
|
||||
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] |
#5
|
|||
|
|||
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 |
#6
|
||||
|
||||
OK, so you want to save the 'metadata' the user inputs into the userform. In that case, as per my previous post:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
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 |
#8
|
|||
|
|||
Hi Paul,
Thank you Regards, Rose |
#9
|
||||
|
||||
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] |
#10
|
|||
|
|||
Hi Paul,
Thanks, want to save us document properties Regards, Rose |
#11
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
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 |
#13
|
||||
|
||||
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:
<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] |
#14
|
|||
|
|||
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 |
#15
|
|||
|
|||
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 |
|
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 |
Force User to Save As | lgillespie | Word | 6 | 09-09-2013 03:13 PM |
User Form | placasse47 | Excel Programming | 3 | 08-01-2012 05:57 AM |