本质上,代码只是在一个充满信息的目录中创建一个文本文件。就像标题说的我可以在 excel 2003 中打开工作表,它会运行良好,但如果它在 2010 年运行,则会弹出一个错误,提示运行时错误“70”权限被拒绝。
这是代码:
Dim i As Integer
Dim dataType As String
Dim dataName As String
Application.ScreenUpdating = False
ChDir ThisWorkbook.Path 'sets the directory to where the workpaper is
ChDir ".." 'Moves up a directory
ChDir (".\folder\")
direct = ThisWorkbook.Path
Worksheets("SchSB XML").Select
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(direct & "\" & flName & ".xml", True)
a.writeline ("<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" _
& Chr(34) & "UTF-8" & Chr(34) & " standalone=" & Chr(34) & "yes" & Chr(34) & "?>")
a.writeline ("<SchSB xmlns:ns1=" & Chr(34) & "http://efast.gov/2011" _
& Chr(34) & " xmlns:xsi=" & Chr(34) & "http://ww.w3.org/2001/XMLSchema-instance" & Chr(34) & ">")
在此之后有一个循环,但它包含与上面相同的 a.writeline 代码,它旋转了大约 100 个单元格
调试显示 Set fs = CreateObject("Scripting.FileSystemObject") 正在破坏并显示权限被拒绝错误。