vba 将值插入 Excel 单元格而不是公式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2412047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Inserting value into Excel cell instead of formula
提问by lucks
I have a VBA script that inserts long strings into Excel cells. In some cases, the string begins with a =. It seems like Excel interprets this as a formula and I get an Out of Memoryerror due to the memory limitations of formulas.
我有一个将长字符串插入 Excel 单元格的 VBA 脚本。在某些情况下,字符串以=. Excel 似乎将其解释为公式,但Out of Memory由于公式的内存限制,我收到错误消息。
How do I tell Excel that I am writing a value, not a formula? Currently, I am doing this:
我如何告诉 Excel 我正在写一个值,而不是一个公式?目前,我正在这样做:
ws.Range("A" & row) = Mid(xml, first, CHUNK_SIZE)
I have tried the following code, but it doesn't work...
我试过下面的代码,但它不起作用......
ws.Range(...).Value = ....
回答by Alex P
Append a 'before the =sign:
'在=符号前附加一个:
Sub Test()
'This returns 30 in cell Al
Range("A1").Value = "=SUM(10,10,10)"
'This shows formula as text in cell A2
Range("A2").Value = "'" & "=SUM(10,10,10)"
End Sub
回答by Jason Punyon
Add an apostrophe 'to the beginning of the string (that excel thinks is a formula) and excel should interpret it as a string instead of a formula.
'在字符串的开头添加撇号(excel认为是公式),excel应该将其解释为字符串而不是公式。

