vba VBscript中的回车?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20535613/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:55:00  来源:igfitidea点击:

Carriage Return in VBscript?

vbams-wordword-vba

提问by n00bAppDev

I am writing a script in VBscript and I need to include line breaks or carriage returns. I was using the following code:

我正在用 VBscript 编写脚本,我需要包含换行符或回车符。我正在使用以下代码:

objSelection.TypeParagraph()

But this creates to big of a space between lines. The best way I can think to explain it is, when you are in Microsoft word, and you type a line, if you were to press Shift + Enter, you would get two separate lines close together, whereas pressing just Enter will do a full Carriage return (which I don't want). I will demonstrate here.

但这会在行之间造成很大的空间。我能想到的最好的解释方法是,当你在 Microsoft word 中输入一行时,如果你按 Shift + Enter,你会得到两行靠在一起的单独的行,而只按 Enter 会做一个完整的回车(我不想要)。我将在这里演示。

How can I achieve the same result as 'Shift + Enter' but through VBscript?

如何通过 VBscript 获得与“Shift + Enter”相同的结果?

Thank you very much.

非常感谢。

采纳答案by Roger Rowland

Assuming you're asking about Word VBA, you can do it like this:

假设你问的是 Word VBA,你可以这样做:

objSelection.TypeText(Chr(11))

Generally, if you can't find out how to do something in VBA that you can do in the application, just record a macro while you perform the required steps and then look and see what VBA has been generated.

通常,如果您无法找到如何在 VBA 中执行您可以在应用程序中执行的操作,只需在执行所需步骤时录制一个宏,然后查看生成的 VBA 内容。