vba 如何格式化标签标题?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7083254/
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
How can I format a label caption?
提问by Andrei Ion
Here's what I want to do. I have a caption that changes every time someone uses the app. The caption is a number... and now it appears like a regular number 123456 ... I want to add "," every 3 digits and I really don't know how to do it because the number doesn't have the same number of digits every time... (I want it to be 123,456 instead of 123456 or 1,234,567... and so on). Thanks!
这就是我想要做的。我有一个标题,每次有人使用该应用程序时都会发生变化。标题是一个数字......现在它看起来像一个普通的数字 123456......我想每 3 位加一个“,”,我真的不知道该怎么做,因为这个数字不一样每次的位数...(我希望它是 123,456 而不是 123456 或 1,234,567...等等)。谢谢!
回答by mwolfe02
I'm assuming you're setting the caption in code, so you can use VBA's format function to do this:
我假设您在代码中设置标题,因此您可以使用 VBA 的格式功能来执行此操作:
Me.MyLabel.Caption = Format(MyNum, "#,##0")