這是將excel單元格寫入XML文件的主要函數的頭文件。我希望這可以調用另一個函數,它可以完成自己的一組寫作。用vba寫兩個函數的文件
Public Sub WriteXML()
Dim Sheet As Worksheet
Dim Cell As Range
Dim xmlFile
xmlFile = ThisWorkbook.Path & "\" & 'Test1' & ".xml"
Set Sheet = ActiveWorkbook.Worksheets("Sht1")
Open xmlFile For Output As #1
Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & _
" encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
Call WriteCustomer(xmlFile)
這是第二個函數的開始,儘管我得到了'找不到對象'的錯誤。
Sub WriteCustomer(x As Variant)
Print x, " <Customer>"
Print x, " <First>" & 'Bill' & "</First>"
Print x, " <Last>" & 'Johnson' & "</Last>"
Print x, " </Customer>"
Print x, ""
End Sub
如何構建調用和/或變量以將打開的文件作爲對象傳遞給第二個函數?
已打開該文件作爲# 1 - 所以你需要打印到#1,而不是xmlFile。 – Floris