通过VBA在PowerPoint中显示文本框的坐标
我想将Word文档中的所有文章转换为PowerPoint演示文稿。通过VBA在PowerPoint中显示文本框的坐标,vba,ms-word,powerpoint,Vba,Ms Word,Powerpoint,我想将Word文档中的所有文章转换为PowerPoint演示文稿。 1篇文章=1张幻灯片(如果文本不适合,请缩小它,否则请创建新幻灯片) 我设法通过文章的文字风格来识别文章的每一部分。我根据文本的样式获取文本,并将其插入幻灯片,等等。我按段落检索文本(Selection.StartOf和EndOf不起作用) 我没有找到一种方法来避免将一个文本覆盖在另一个文本上 也许我可以通过文本框的坐标得到我需要的东西 到目前为止,我得到的是: ActiveDocument.段落中每个StyleInWord的
1篇文章=1张幻灯片(如果文本不适合,请缩小它,否则请创建新幻灯片) 我设法通过文章的文字风格来识别文章的每一部分。我根据文本的样式获取文本,并将其插入幻灯片,等等。我按段落检索文本(Selection.StartOf和EndOf不起作用) 我没有找到一种方法来避免将一个文本覆盖在另一个文本上 也许我可以通过文本框的坐标得到我需要的东西 到目前为止,我得到的是: ActiveDocument.段落中每个StyleInWord的
如果StyleInWord.Style=“文章的名称”,则
wordText0=StyleInWord.Range
设置pptLayout=pptPres.SlideMaster.CustomLayouts.Add(ppLayoutBlank)
设置pptSlide=pptPres.Slides.AddSlide(1,pptLayout)
如果pptPres.Slides(1).Shapes(1).HasTextFrame则
pptPres.幻灯片(1).形状(1).删除
如果结束
使用pptPres.PageSetup
.SlideSize=ppSlideSizeCustom
.滑动高度=厘米停止点(21.008)
.SlideWidth=厘米停止点(28.011)
以
设置mySlide=pptPres.Slides(1.Shapes.AddTextbox)(msoTextOrientationHorizontal,厘米停止点(1.31),厘米停止点(3.73),厘米停止点(24.34),厘米停止点(12.57))
使用mySlide.TextFrame.TextRange
.Text=wordText0
使用.Font
.尺寸=11'点
.Name=“Arial”
.Bold=msoTrue
以
以
如果结束
如果StyleInWord.Style=“文章的描述”,则
wordText1=StyleInWord.Range
设置mySlide=pptPres.Slides(1.Shapes.AddTextbox)(msoTextOrientationHorizontal,厘米停止点(1.31),厘米停止点(5.73),厘米停止点(24.34),厘米停止点(12.57))
使用mySlide.TextFrame
使用.TextRange
.Text=wordText1
使用.Font
.尺寸=11'点
.Name=“Arial”
.Bold=msoTrue
以
以
以
如果结束
如果StyleInWord.Style=“文章的主文本”,则
设置mySlide=pptPres.Slides(1.Shapes.AddTextbox)(msoTextOrientationHorizontal,厘米停止点(1.31),厘米停止点(7.73),厘米停止点(24.34),厘米停止点(12.57))
wordText2=StyleInWord.Range
使用mySlide.TextFrame
使用.TextRange
.Text=wordText2
使用.Font
.尺寸=11'点
.Name=“Arial”
.Bold=msoTrue
以
以
以
如果结束
下一个StyleInWord
'在这里,我更改了顺序,因此我创建的第一张幻灯片将在forEachLoop结束时保持第一张幻灯片
i=1
对于i=1到pptPres.Slides.Count
pptPres.幻灯片(i).移动到1
接下来我
每次添加文本框时,您都会将顶部位置设置为比上一个位置低2厘米。这不考虑上一个文本框的高度
有一个非常简单的解决方案。文本框具有top和height属性,因此只需将它们存储在变量中即可。这样,您就可以在上一个文本框的正下方添加每个新文本框
您的代码还需要一些改进,因为您正在进行的一些演示设置应该在循环之外。还应将mySlide
重命名为pptTextBox
,以便变量具有与其他变量一致的逻辑名称
Set-pptLayout=pptPres.SlideMaster.CustomLayouts.Add(ppLayoutBlank)
不做您认为它做的事情,也没有必要。演示文稿将已经包含一个空白布局,该布局的名称为“blank”,因此您只需设置指向它的指针,同样位于循环之外
'do presentation setup outside the loop
With pptPres.PageSetup
.SlideSize = ppSlideSizeCustom
.SlideHeight = CentimetersToPoints(21.008)
.SlideWidth = CentimetersToPoints(28.011)
End With
'a presentation will already include a blank layout so there is no need to create one
For Each pptLayout In pptPres.SlideMaster.CustomLayouts
If pptLayout.Name = "Blank" Then Exit For
'pptLayout now points to the Blank layout
Next
For Each StyleInWord In ActiveDocument.Paragraphs
If StyleInWord.Style = "NAME_OF_THE_ARTICLE" Then
wordText0 = StyleInWord.Range
Set pptSlide = pptPres.Slides.AddSlide(1, pptLayout)
If pptPres.Slides(1).Shapes(1).HasTextFrame Then
pptPres.Slides(1).Shapes(1).Delete
End If
Set pptTextBox = _
pptPres.Slides(1).Shapes.AddTextbox(msoTextOrientationHorizontal, _
CentimetersToPoints(1.31), CentimetersToPoints(3.73), _
CentimetersToPoints(24.34), CentimetersToPoints(12.57))
With pptTextBox
With .TextFrame.TextRange
.Text = wordText0
With .Font
.Size = 11 ' points
.Name = "Arial"
.Bold = msoTrue
End With
End With
textBoxTop = .Top
textBoxHeight = .Height
End With
End If
If StyleInWord.Style = "DESCRIPTION_OF_THE_ARTICLE" Then
wordText1 = StyleInWord.Range
Set pptTextBox = _
pptPres.Slides(1).Shapes.AddTextbox(msoTextOrientationHorizontal, _
CentimetersToPoints(1.31), textBoxTop + textBoxHeight, _
CentimetersToPoints(24.34), CentimetersToPoints(12.57))
With pptTextBox
With .TextFrame.TextRange
.Text = wordText1
With .Font
.Size = 11 ' points
.Name = "Arial"
.Bold = msoTrue
End With
End With
textBoxHeight = textBoxHeight + .Height
End With
End If
If StyleInWord.Style = "MAIN_TEXT_OF_THE_ARTICLE" Then
Set pptTextBox = _
pptPres.Slides(1).Shapes.AddTextbox(msoTextOrientationHorizontal, _
CentimetersToPoints(1.31), textBoxTop + textBoxHeight, _
CentimetersToPoints(24.34), CentimetersToPoints(12.57))
wordText2 = StyleInWord.Range
With pptTextBox
With .TextFrame.TextRange
.Text = wordText2
With .Font
.Size = 11 ' points
.Name = "Arial"
.Bold = msoTrue
End With
End With
textBoxHeight = textBoxHeight + .Height
End With
End If
Next StyleInWord
'Here i change the order, so the first slide i create will stay the first by the end of the forEachLoop
i = 1
For i = 1 To pptPres.Slides.Count
pptPres.Slides(i).MoveTo 1
Next i
事实上,这很有帮助。感谢您对我来自automation sphere的“Code Tone”的评论,有很多东西需要学习。非常感谢你!我也在想。现在有了上面的代码a,我得到了我需要的所有段落,但我也复制了一个“回车”符号,作为空行出现在演示文稿中,你有什么想法吗?@TahirRuzbaev-在你将文本分配给字符串之后,将字符串缩短一个字符,例如
wordText0=Left(wordText0,Len(wordText0)-1)
同样有效,谢谢你@Timothy Rylatt。也许你能帮我解释一下这个程序的另一个逻辑。现在,如果文本不适合幻灯片,我需要缩小文本(我可以这样做,但是适用于整个幻灯片,我只需要用于正文),我想在每个正文段落中添加一个标记,然后尝试使用它。但是有人可以建议另一种方法吗?@TahirRuzbaev-你需要把它作为一个新问题发布。