VBA read Excel Write XML

Source: Internet
Author: User

Vba

Write a file
Dim SFile As Object, FSO as Object
Set fso = CreateObject ("Scripting.FileSystemObject")

Sfile.writeline (String (8, "") & "<Request>")

Sfile.close
Set SFile = Nothing
Set FSO = Nothing

Select Folder
With Application.filedialog (msoFileDialogFolderPicker)
If. Show =-1 Then
folder =. SelectedItems (1)

End If
End with
MsgBox Folder & "/taskinfo.xml"


Cyclic/if
Do While Cells (RowIndex, 2). Value <> ""
For compcol = 8 to + Step 1

If Idstr < Ten Then
Sfile.writeline (String ("") & "<complete id=" "0" & idstr & ""/> ")
Else
Sfile.writeline (String ("") & "<complete id=" "" & Idstr & ""/> ")
End If

Next Compcol

Loop


Complete


Sub CreateFile ()

Dim SFile As Object, FSO as Object
Set fso = CreateObject ("Scripting.FileSystemObject")

folder = "D:"

With Application.filedialog (msoFileDialogFolderPicker)
If. Show =-1 Then
folder =. SelectedItems (1)

End If
End with
MsgBox Folder & "/taskinfo.xml"

Set sFile = fso. CreateTextFile (Folder & "/taskinfo.xml", True)

Sfile.writeline ("<?xml version=" "1.0" "encoding=" "UTF-8" "?>")
Sfile.writeline ("<Tasks>")

RowIndex = 4

Do While Cells (RowIndex, 2). Value <> ""
' タスクid
TaskId = Cells (RowIndex, 2). Value

' Home electricity's really into elephant
obj = Cells (RowIndex, 4). Value

Sfile.writeline (String (4, "") & "<task id=" "" & TaskId & "" obj= "" "& Obj &" ">"

Sfile.writeline (String (8, "") & "<Request>")


For compcol = 8 to + Step 1
' Supplemental ID
Compid = Cells (RowIndex, Compcol). Value

If compid <> "Then

Idstr = compCol-7
If Idstr < Ten Then
Sfile.writeline (String ("") & "<complete id=" "0" & idstr & ""/> ")
Else
Sfile.writeline (String ("") & "<complete id=" "" & Idstr & ""/> ")
End If

End If

Next Compcol


Sfile.writeline (String (8, "") & "</Request>")

' URL
URL = Cells (RowIndex, 5). Value

' Path
Path = Cells (RowIndex, 6). Value

' Method
method = Cells (RowIndex, 7). Value

Sfile.writeline (String (8, "") & "<api url=" "" & URL & "" Path= "" "& Path &" "Method=" "" & Method & "" > ")

Sfile.writeline (String ("") & "<Input>")

' into force definition
Inputtext = Cells (RowIndex, 18). Value

Sfile.writeline (Inputtext)

Sfile.writeline (String ("") & "</Input>")

Sfile.writeline (String (8, "") & "</Api>")

Sfile.writeline (String (8, "") & "<Response>")

' Output 対応 answer
Outputstatus = Cells (RowIndex, 19). Value

Sfile.writeline (Outputstatus)

Sfile.writeline (String (8, "") & "</Response>")

Sfile.writeline (String (4, "") & "</Task>")

Sfile.writeline

RowIndex = RowIndex + 1

Loop


Sfile.writeline ("</Tasks>")
Sfile.close
Set SFile = Nothing
Set FSO = Nothing
End Sub


Sub DeleteFile ()

Dim FSO as Object
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso. DeleteFile ("D:/testfile.txt")
End Sub

VBA read Excel Write XML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.