Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA PowerPoint 2013中的文本对齐_Vba_Powerpoint_Powerpoint 2013 - Fatal编程技术网

VBA PowerPoint 2013中的文本对齐

VBA PowerPoint 2013中的文本对齐,vba,powerpoint,powerpoint-2013,Vba,Powerpoint,Powerpoint 2013,我有一个代码片段,它工作得很好,除了最后一行,当我尝试将文本对齐到中心时。msoAlignRight只是为了测试,看看它是否向右移动。但是什么都没有发生编辑:我已经将它从Qlikview合并到PPT宏中,但这并不重要 注:我希望LeXT 0以中间文本为中心。现在它在左边 Sub ppt 'Set ppt template filePath_template = "...\Template.pptx" 'Remove filters ActiveDocument.ClearAll() 'Re

我有一个代码片段,它工作得很好,除了最后一行,当我尝试将文本对齐到中心时。msoAlignRight只是为了测试,看看它是否向右移动。但是什么都没有发生编辑:我已经将它从Qlikview合并到PPT宏中,但这并不重要

注:我希望LeXT 0以中间文本为中心。现在它在左边

Sub ppt

'Set ppt template
filePath_template = "...\Template.pptx"

'Remove filters
ActiveDocument.ClearAll()

'Retrieve all accounts
set field1Values = ActiveDocument.Fields("name").GetPossibleValues 


 ActiveDocument.ActivateSheetByID "ABC01"
for i = 0 to 15
ActiveDocument.Fields("name").Clear
ActiveDocument.GetApplication.WaitForIdle 100
'Set filter on just 1 account
ActiveDocument.Fields("name").Select field1Values.Item(i).Text

ActiveDocument.GetApplication.Sleep 5000

ActiveDocument.GetApplication.WaitForIdle 100
'Create a ppt object
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
'Open the ppt template 
Set objPresentation = objPPT.Presentations.Open(filePath_template)

Set PPSlide = objPresentation.Slides(1)

'leText 2
ActiveDocument.GetSheetObject("TEXT001").CopyTextToClipboard
ActiveDocument.GetApplication.WaitForIdle 100
Set leText2 = PPSlide.Shapes.Paste
leText2.Top = 280
leText2.Left = 310
leText2.Width = 300
leText2.TextFrame.TextRange.Font.Size = 8

ActiveDocument.GetApplication.Sleep 1000

for k = 0 to 10
ActiveDocument.GetApplication.WaitForIdle 100
ActiveDocument.ActiveSheet.CopyBitmapToClipboard
ActiveDocument.GetApplication.WaitForIdle 100
next

ActiveDocument.GetApplication.WaitForIdle 100

'leText 0
ActiveDocument.GetSheetObject("TEXT002").CopyTextToClipboard
ActiveDocument.GetApplication.WaitForIdle 100
Set leText0 = PPSlide.Shapes.Paste
leText0.Top = 1
leText0.Left = 150
leText0.Width = 700
leText0.TextFrame.TextRange.Font.Size = 12
leText0.TextFrame.TextRange.Font.Color = vbWhite

'Save ppt
filePath = "...\SaveFolder\" & field1Values.Item(i).Text & ".pptx"
objPresentation.SaveAs filePath
Next
objPPT.Quit

End Sub
将“右对齐”行更改为:

leText.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignRight
另一个可能的代码改进是将
结合使用,如:

With leText
    .Top = 12
    .Left = 250
    .Width = 500
    .TextFrame.TextRange.Font.Size = 14
    .TextFrame.TextRange.Font.Color = vbWhite
    .TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignRight
End With

您声明leText为哪种变量类型?在处理单个对象时,它应该是Shappe,但粘贴方法将返回ShaperAge类型的对象,因此您可以使用以下行获取单个形状:

Set leText = PPSlide.Shapes.Paste(1)
另外,如果此代码在Excel中运行,并且您正在使用早期绑定,我假设您已经设置了对PowerPoint库的引用,以便知道正确的值,如果使用后期绑定,您需要自己定义它


最后,对于MSO 2007及以上版本,我建议使用更新的TextFrame2(和TextRange2)对象,因为它们具有更新的图形引擎提供的更多属性。

由于CopyTextToClipboard方法是QV API,我不确定是复制形状还是形状(或TextRange)中的文本。尝试以下操作:宏创建形状leText0后,在PowerPoint中选择它,将对正设置为左侧,然后在即时窗口中输入以下命令: ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.ParagraphFormat.Alignment=pAlignCenter

请注意,ppAlignCenter=2

会发生什么

如果API只是复制文本,那么我希望您首先需要在PowerPoint中创建形状,然后将文本从剪贴板复制到形状的TextRange中。要测试此情况,请更换以下管路:

'leText 2
ActiveDocument.GetSheetObject("TEXT001").CopyTextToClipboard
ActiveDocument.GetApplication.WaitForIdle 100
Set leText2 = PPSlide.Shapes.Paste
leText2.Top = 280
leText2.Left = 310
leText2.Width = 300
leText2.TextFrame.TextRange.Font.Size = 8
……有了这些:

'leText 2
ActiveDocument.GetSheetObject("TEXT001").CopyTextToClipboard
ActiveDocument.GetApplication.WaitForIdle 100
With PPSlide.Shapes.AddShape(msoShapeRectangle, 310, 280, 300, 0)
  With .TextFrame
    .WordWrap = msoFalse
    .AutoSize = ppAutoSizeShapeToFitText
    With .TextRange
      .Paste
      .ParagraphFormat.Alignment = ppAlignCenter
      .Font.Size = 8
    End With
  End With
End With

试试我下面的代码,让我知道它是否有效。嗨,是的,它不起作用。我也试过:(您收到错误消息了吗?您确实注意到您正在将文本更改为白色,因此很难看到字体。它是什么类型的对象?文本框?表格?它是更大代码的一部分,因此背景是黑色的。但是我将此对齐方式放在末尾,但它没有任何作用。如果我将其放在前面,例如font.Size,它就停在那里。)。只是停止处理代码。它只是从Qlikview复制文本,因此它是常规的textbox@Probs你能上传剩下的相关代码吗?是不是太长了?不,它确实很长而且不相关。嗨,ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.ParagraphFormat.Alignment=pAlignCenter可以工作,但是..Qlikview似乎不行当我将您的代码替换为我的代码时,请识别With函数。如果没有Qlikview,我如何运行ppAlignCenter?它只针对所有Powerpoints运行?我现在不确定我是否理解QV!您是否在Microsoft VBE中编辑VBA?哦,实际上不是在Qlikview中。但是,我也尝试为所有打开的powerp运行该特定代码段打开文件,但未成功。它只能对已打开的选定powerpoint执行此操作-仅一个。