我是编写vb脚本的新手。我能够从excel复制文本(或范围)并将其粘贴到powerpoint中,我想更改字体大小(到12),放置边框并将背景设置为白色。以下是我必须从excel中复制文本的内容:
' ~~~~~~~~~~~~~
Sub Copy_ExcelText_Powerpoint_and_Format()
' This copies a range in excel and copy it in Powerpoint, and then formats it
Dim PPApp As Object ' As PowerPoint.Application
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
Sheets("Sheet1").Range("J2:J4").copy
PPApp.ActivePresentation.Slides(1).Shapes.PasteSpecial DataType:=10, Link:=0
' now format the text
' .......
' ~~~~~~~~~~~~~
我发现了一些脚本会改变活动幻灯片中所有文本的字体,但我只想更改刚从excel复制的文本的字体大小(等)。任何帮助将受到高度赞赏。非常感谢!
可能是3,2014编辑
你好,我已经想到了一种不同的方法,我会做一个AddTextbox而不是粘贴,但它给了我一个"运行时错误13类型不匹配"错误。
下面是修改后的脚本: ' ~~~~~~~~~~~~~ Sub Copy_ExcelText_Powerpoint_and_Format() '这将复制excel中的范围并将其复制到Powerpoint中,然后对其进行格式化 Dim PPApp As Object'作为PowerPoint.Application
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
'Sheets("Sheet1").Range("J2:J4").copy --commented out
'PPApp.ActivePresentation.Slides(1).Shapes.PasteSpecial DataType:=10, Link:=0--commented out
' use addtextbox instead
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
With PPSlide
' create textbox
Set tBox = .Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=1, _
Top:=250, _
Width:=720, _
Height:=100)
' set content
tBox.TextFrame.TextRange.Text = Sheets("Sheet1").Range("M2").Value
' Set format
tBox.Font.Bold = False
tBox.Font.Name = "Arial (Headings)"
tBox.Font.Size = 12
tBox.ParagraphFormat.Alignment = ppAlignCenter
End With
感谢我能得到的任何帮助。感谢。