write to Xml

Dossfm0q

Banned User
Joined
Mar 9, 2009
Messages
570
Office Version
  1. 2019
Platform
  1. Windows
what wrong I have

Code:
Public Sub Creat()


Dim docPropsXML As String
Dim docPropsFolder As String
'Creating the Document Properties
FilePath = ThisWorkbook.Path & "\"
RootFolder = FilePath & "root"
docPropsFolder = RootFolder & "\" & "docProps"
If Len(Dir(RootFolder, vbDirectory)) = 0 Then MkDir RootFolder
If Len(Dir(docPropsFolder, vbDirectory)) = 0 Then MkDir docPropsFolder
docPropsXML = "<!--?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?--> " & vbNewLine & _
"<properties xmlns=" & vbNewLine & _
"  ="" ""http:="" schemas.openxmlformats.org="" officedocument="" 2006="" extended-properties""="" "="" &="" vbnewline="" _
"   xmlns:vt=""http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes""> " & vbNewLine & _
"    <template>Normal.dotm</template> " & vbNewLine & _
"    <totaltime>1</totaltime> " & vbNewLine & _
"    
1 " & vbNewLine & _
"    <words>3</words> " & vbNewLine & _
"    <characters>23</characters> " & vbNewLine & _
"    <application>Microsoft Office Word</application> " & vbNewLine & _
"    <docsecurity>0</docsecurity> " & vbNewLine & _
"    <lines>1</lines> " & vbNewLine & _
"    
1 " & vbNewLine & _
"    <scalecrop>false</scalecrop> " & vbNewLine & _
"    <company>MS</company> " & vbNewLine & _
"    <linksuptodate>false</linksuptodate> " & vbNewLine & _
"    <characterswithspaces>25</characterswithspaces> " & vbNewLine & _
"    <shareddoc>false</shareddoc> " & vbNewLine & _
"    <hyperlinkschanged>false</hyperlinkschanged> " & vbNewLine & _
"    <appversion>12.0000</appversion> " & vbNewLine & _
" </properties>"




Call ToText(docPropsXML, docPropsFolder, "app", "xml")




End Sub
Public Sub ToText(TXT As String, Path As String, FileName As String, Ext As String)


 Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object


    Dim objShell As Object
    Dim strWordExe As String
    Set objShell = CreateObject("WScript.Shell")
    strWordExe = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe\")


On Error Resume Next
'Path = CreateObject("WScript.Shell").SpecialFolders("Desktop")
'Ext = "doc" ' or Ext="CV"
Set Fileout = fso.CreateTextFile(Path & "\" & FileName & "." & Ext, True, True)
  On Error GoTo 0
  On Error Resume Next


         Fileout.Write TXT
    Fileout.Close
    
    If InStr(1, Ext, "txt", vbTextCompare) > 0 Then Shell "Notepad" & " " & Path & "\" & FileName & "." & Ext, vbMaximizedFocus
    If InStr(1, Ext, "DOc", vbTextCompare) > 0 Then Shell strWordExe & " " & Path & "\" & FileName & "." & Ext, vbMaximizedFocus
    If InStr(1, Ext, "htm", vbTextCompare) > 0 Then Shell "explorer.exe " & Path & "\" & FileName & "." & Ext, vbNormalFocus
End Sub


https://msdn.microsoft.com/en-us/library/bb266220(v=office.12).aspx#office2007wordfileformat_creatingthedocument
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,215,427
Messages
6,124,831
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top