如何使用 VBA 从 Excel 文件将 & 符号写入 XML 文件? [英] How to write an ampersand to an XML file from an Excel file using VBA?

查看:47
本文介绍了如何使用 VBA 从 Excel 文件将 & 符号写入 XML 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是 VBA 的完全新手,但不幸的是我被抛弃了这段代码,我不得不处理它...

First of all, I'm a complete newbie when it comes to VBA, but unfortunately I was dumped this code and I have to deal with it...

应用程序所做的是复制 Excel xlsm 文件中的信息并将其粘贴到 XML 文件中以供进一步处理.

What the application does is copy the information inside an Excel xlsm file and paste it in an XML file for further processing.

事情是,一切都非常顺利,直到我在其中一个 Excel 单元格中打了一个&符号,即:

The thing is, it all goes very smooth until I hit an ampersand in one of the Excel cells, i.e.:

我有一个带有R&D"的单元格,当我将它传递给 XML 文件时,出现以下错误:

I have a cell which has "R&D" and when I'm passing it to the XML file I get the following error:

Run-time error '91':
Object variable or With block variable not set

请记住,我对 VBA 完全是垃圾.我尝试更改R&&D"、R&D"单元格中的内容,但没有骰子.

Bear in mind I'm complete garbage with VBA. I tried changing the contents in the cells for "R&&D", "R&D" but no dice.

我相信单元格的值来自这行代码:

I believe the value of the cell comes from this line of code:

oCell.Offset(, 0).Value

但我想要一些关于如何摆脱&符号的帮助......

but I would like some help as to how escape the ampersands...

非常感谢,如果您需要更多信息,请告诉我.

Many thanks in advance, if you need more information, let me know.

推荐答案

您要寻找的是一种在字符串中创建 html 实体的方法,这涉及使用 & 和任何特殊代码人物.'&'本身就是一个特殊的字符.

What your looking for is a way to create html entities in the string, this involves using & and a code for any special characters. '&' is a special char itself.

可能有代码可以更改以执行此操作,但同时在您的代码中替换

There may be code out there to change to do this, but in the meantime in your code replace

&

&

你应该解决那个特定的问题.

and you should solve that particular problem.

这篇关于如何使用 VBA 从 Excel 文件将 & 符号写入 XML 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆