Sub TestWriteXML() Dim FFileA As Long Dim exeFile As String FFileA = FreeFlie Open "c:\Users\hp\Desktop\code\exefiles.xml" For Output As #FFileA Print #FFileA, "<?xml version=""1.0""?>" Print #FFileA, "<?mso-application progid=""Excel.sheet""?>""" Print #FFileA, "<Workbook xmlns=""urn:schemas-microsoft-" & "com:office:spreadsheet"">" Print #FFileA, " <Worksheet ss:Name=""EXE Files"">" Print #FFileA, " <Table>" exeFile = Dir("C:\Users\hp\Desktop\code\*.txt") While exeFile <> "" Print #FFileA, " <Row>" Print #FFileA, " <Cell><Data ss:Type=""String"">" & "</Data></Cell>" Print #FFileA, " <Cell><Data ss:Type=""String"">" & FileDateTime("C:\Users\hp\Desktop\cod\" & exeFile) & "</Data></Cell>" Print #FFileA, " <Row>" exeFile = Dir Wend Print #FFileA, " </Table>" Print #FFileA, " </Worksheet>" Print #FFileA, " </Workbook>" Close #FFileA End Sub
这是《学习MS VBA》书中第九章的例子,我将目录名改成了本机上的目录。
运行后显示问题。
然后我想可能是修改了目录名的原因,所以我找到了书配光盘里的代码再运行,发现这问题依然存在。(下面是光盘中的代码)
Sub TestWriteASCIIE() Dim FFileA As Long Dim exeFile As String FFileA = FreeFile Open "c:\exefiles.xml" For Output As #FFileA Print #FFileA, "<?xml version=""1.0""?>" Print #FFileA, "<?mso-application progid=""Excel.Sheet""?>""" Print #FFileA, _ "<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet"">" Print #FFileA, " <Worksheet ss:Name=""EXE Files"">" Print #FFileA, " <Table>" exeFile = Dir("C:\Windows\System32\*.exe") While exeFile <> "" Print #FFileA, " <Row>" Print #FFileA, _ " <Cell><Data ss:Type=""String"">" & exeFile & "</Data></Cell>" Print #FFileA, _ " <Cell><Data ss:Type=""String"">" & _ FileDateTime("C:\Windows\System32\" & exeFile) & "</Data></Cell>" Print #FFileA, " </Row>" exeFile = Dir Wend Print #FFileA, " </Table>" Print #FFileA, " </Worksheet>" Print #FFileA, "</Workbook>" Close FFileA End Sub
请教各位老师是什么问题呢?