首先,就 VBA 而言,我是一个完全的新手,但不幸的是我被丢弃了这段代码,我不得不处理它......
应用程序所做的是复制 Excel xlsm 文件中的信息并将其粘贴到 XML 文件中以供进一步处理。
事情是,一切都非常顺利,直到我在其中一个 Excel 单元格中点击了一个符号,即:
我有一个包含“R&D”的单元格,当我将它传递给 XML 文件时,出现以下错误:
Run-time error '91':
Object variable or With block variable not set
请记住,我完全是 VBA 的垃圾。我尝试更改“R&&D”、“R&
D”单元格中的内容,但没有骰子。
我相信单元格的值来自这行代码:
oCell.Offset(, 0).Value
但我想得到一些关于如何转义 & 符号的帮助...
非常感谢,如果您需要更多信息,请告诉我。
最佳答案
我为 Access 编写了以下函数,但它应该适用于 Excel。
Function CleanupStr(strXmlValue) As String
'description: Replace forbidden char. &'"<> by their Predefined General Entities
'author: Patrick Honorez - www.idevlop.com
Dim sValue As String
If IsNull(strXmlValue) Then
CleanupStr = ""
Else
sValue = CStr(strXmlValue)
sValue = Replace(sValue, "&", "&") 'do ampersand first !
sValue = Replace(sValue, "'", "'")
sValue = Replace(sValue, """", """)
sValue = Replace(sValue, "<", "<")
sValue = Replace(sValue, ">", ">")
CleanupStr = sValue
End If
End Function
关于xml - 如何使用 VBA 将 Excel 文件中的符号写入 XML 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13919677/