excel VBA - 返回包含转义撇号的单元格值 [英] excel VBA - return cell value that includes the escaping apostrophe
本文介绍了excel VBA - 返回包含转义撇号的单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
'= Foo
和 = Foo
的单元格,获取属性 .Value
, .Value2
, .Text
, .Formula
都给我两个范围的 = Foo
。 如何将转义撇号,以便在返回单元格值时得到'= Foo
解决方案
p>使用 .PrefixCharacter
获取隐藏的撇号。
像这样:调试。打印范围(A1)。前缀字符
它,这个 Microsoft Post 可能会有帮助。
完整示例:
子测试()
Dim wks As Worksheet
设置wks =工作表(Sheet1)
Dim rng As Range
设置rng = wks.Range(A1)
如果不是rng.HasFormula T hen
如果rng.PrefixCharacter<> 然后
MsgBox单元格值是:& rng.PrefixCharacter& rng.Text
Else
MsgBox在单元格中没有前缀值& rng.Address
如果
结束If
End Sub
Given two cells with contents '=Foo
and =Foo
, getting the properties .Value
,.Value2
, .Text
, .Formula
all give me =Foo
for both ranges.
How do I include the escaping apostrophe so that I get '=Foo
when returning the cell value?
解决方案
Use .PrefixCharacter
to get the hidden apostrophe.
Like this: Debug.Print Range("A1").PrefixCharacter
Depending on what your trying to do with it, this Microsoft Post might be helpful.
Full Example:
Sub test()
Dim wks As Worksheet
Set wks = Worksheets("Sheet1")
Dim rng As Range
Set rng = wks.Range("A1")
If Not rng.HasFormula Then
If rng.PrefixCharacter <> "" Then
MsgBox "Cell value is: " & rng.PrefixCharacter & rng.Text
Else
MsgBox "No prefix value in cell " & rng.Address
End If
End If
End Sub
这篇关于excel VBA - 返回包含转义撇号的单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文