简体   繁体   English

Excel VBA InputBox值不是日期

[英]Excel VBA InputBox value is not a date

I have a user input box where you type in a string, annoyingly this string looks like a date 00/00/0000 and excel reformats it as such. 我有一个用户输入框,您在其中输入一个字符串,但令人讨厌的是,该字符串看起来像一个日期00/00/0000 ,因此excel将其重新格式化。 When the value can't be a date ex. 当值不能为日期时。 18/19/4561 (month can't be 18 or 19) it displays it correctly. 18/19/4561 (月份不能为18或19),它可以正确显示。 But whenever it can be seen as a possible date it switches things around. 但是只要有可能,它就会改变一切。

I've tried setting the value as a string rather than nothing but excel still changes it when putting it in the page. 我尝试将值设置为字符串而不是什么,但是excel在将其放入页面时仍会更改它。

When I try manually inputting it in the cell or equal the values from a manually entered cell it works fine. 当我尝试在单元格中手动输入或等于手动输入的单元格中的值时,它可以正常工作。

But whenever I get it from the inputbox it messes with it. 但是,每当我从输入框获得它时,它就会混乱。 Even when I hard code the string to a variable ( x = "05/06/4564" ) it switches things around. 即使当我将字符串硬编码为一个变量( x = "05/06/4564" )时,它x = "05/06/4564"切换内容。

How do I force excel to leave the string as is? 如何强制Excel保留字符串原样?

Prefix the value with a single apostrophe and Excel will interpret it as a string. 用单撇号前缀值,Excel会将其解释为字符串。

Eg '18/19/4561 例如'18/19/4561

Also, have you tried setting the cell format to Text 另外,您是否尝试过将单元格格式设置为“ Text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM