确定是否输入了带前导单引号的字符串 [英] Determining if a string has been entered with a leading single quote

查看:72
本文介绍了确定是否输入了带前导单引号的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是由于我试图回答这个问题:

This question arose in my attempt to answer this question:

在空白工作簿中,将A1:A2设置为文本格式.在A1中键入123,在A2中键入'123.两者都导致字符串"123"是单元格值:

In a blank workbook, format A1:A2 as text. In A1 type 123 and in A2 type '123. Both result in the string "123" being the cell value:

但是-公式栏在选择A2时显示文本'123,但在选择A1时仅显示123,因此Excel保留有关字符串的信息被输入.可以从VBA访问此信息吗?

But -- the formula bar displays the text '123 when A2 is selected but only displays 123 when A1 is selected, so Excel retains the information about how the strings were entered. Can this information be accessed from VBA?

一项快速测试,显示什么无效:

A quick test which shows what doesn't work:

Sub test()
    Dim R As Range, S As Range
    Set R = Range("A1")
    Set S = Range("A2")
    Debug.Print R.Value = S.Value
    Debug.Print R.Value2 = S.Value2
    Debug.Print R.Text = S.Text
    Debug.Print R.Formula = S.Formula
    Debug.Print R.FormulaLocal = S.FormulaLocal
    Debug.Print R.FormulaR1C1 = S.FormulaR1C1
    Debug.Print R.FormulaR1C1Local = S.FormulaR1C1Local
End Sub 

除了重复打印True之外,此操作无济于事.我想不出其他任何相关的范围属性.我看不到任何允许访问公式栏上显示的文本的应用程序或工作表级别的对象.有什么想法吗?

This does nothing but repeatedly print True. I can't think of any other range properties that would be relevant. I don't see any application or worksheet level object which allows one to access the text displayed in the formula bar. Any ideas?

推荐答案

您可以使用RangePrefixCharacter属性访问撇号.

You can use the PrefixCharacter property of Range to access the apostrophe.

Debug.Print [A1].PrefixCharacter ' prints blank line
Debug.Print [A2].PrefixCharacter ' prints apostrophe

这篇关于确定是否输入了带前导单引号的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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