使用 VBA 更改 PowerPoint 演示文稿中的默认文本方向

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

Change default text direction in a powerpoint presentation using VBA

vbatextpowerpointpowerpoint-vbaright-to-left

提问by Arie Livshin

I use the Powerpoint Object-Model to programmatically create a presentation in PowerPoint 2007.

我使用 Powerpoint 对象模型在 PowerPoint 2007 中以编程方式创建演示文稿。

Some of the computers on which I run my program have PowerPoint set with Hebrew as the Primary Editing Language. (to change the primary language, push the "Office" button, then "Powerpoint options", and go to Popular->Language Settings->Primary Editing Language)

我运行我的程序的一些计算机将 PowerPoint 设置为希伯来语作为主要编辑语言。(要更改主要语言,请按“Office”按钮,然后按“Powerpoint 选项”,然后转到“流行”->“语言设置”->“主要编辑语言”)

On these computers, when I run my program, all the text in the created presentation (wrongly) appears right-justified and the bullets appear to the right of the text.

在这些计算机上,当我运行我的程序时,创建的演示文稿中的所有文本(错误地)都显示为右对齐,并且项目符号出现在文本的右侧。

I could fix this by editing the ppt/presentation.xml in the resulting presentation PPTX file. I adjust the Alignment and RightToLeft properties in the "Default Text Styles" for each bullet level. However, XML editing is not a good option for this project.

我可以通过编辑生成的演示文稿 PPTX 文件中的 ppt/presentation.xml 来解决这个问题。我为每个项目符号级别调整了“默认文本样式”中的 Alignment 和 RightToLeft 属性。但是,XML 编辑对于这个项目来说并不是一个好的选择。

How can I change the default text direction in a presentation using the Object Model (i.e., VBA), besides changing each TextBox individually?

除了单独更改每个文本框之外,如何使用对象模型(即 VBA)更改演示文稿中的默认文本方向?



Thanks for the suggestions,

谢谢你的建议,

What I tried:

我试过的:

I performed Application.Presentations(1).LayoutDirection = ppDirectionLeftToRight, which changes the direction of the PowerPoint user-interface. I also changed Application.Presentations(1).LanguageIDto US English. Unfortunately, doing these things did not solve the problem of the right-to-left text in the created presentation.

我执行了Application.Presentations(1).LayoutDirection = ppDirectionLeftToRight,它改变了 PowerPoint 用户界面的方向。我也改成Application.Presentations(1).LanguageID了美式英语。不幸的是,做这些事情并没有解决创建的演示文稿中从右到左的文本问题。

So finally I gave up on changing the parameters for the Presentation itself and indeed directly changed ParagraphFormat.TextDirectionand ParagraphFormat.Alignmentfor each Runof each TextBox which I initially tried to avoid, and naturally this had the desired effect.

所以最后我放弃了改变参数的演讲本身,事实上直接更改ParagraphFormat.TextDirection,并ParagraphFormat.Alignment为每个Run我最初试图避免每次文本框的,自然这有预期的效果。

回答by Dudi

In C# it will look this way:

在 C# 中,它看起来像这样:

textbox.TextFrame.TextRange.ParagraphFormat.TextDirection = PpDirection.ppDirectionRightToLeft