请问如何用vb创建一个ppt文件,并且向里面添加内容?

montenu 2003-09-23 09:13:45
非常感谢
...全文
239 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
montenu 2003-09-23
  • 打赏
  • 举报
回复
我找到原因了,我的PWRPNT9.POT为PWRPNT10.POT
谢谢
TechnoFantasy 2003-09-23
  • 打赏
  • 举报
回复
对,你在硬盘上找一个.pot文件就可以了,也可以不用模版打开的。
montenu 2003-09-23
  • 打赏
  • 举报
回复
是不是指定的模板不存在?

如何换一个模板

montenu 2003-09-23
  • 打赏
  • 举报
回复
运行到Set oPres = oApp.Presentations.Open(sTemplate, , , True)时提示
“power point could not open the file"

shibushi
montenu 2003-09-23
  • 打赏
  • 举报
回复
再次非常感谢

TechnoFantasy 2003-09-23
  • 打赏
  • 举报
回复
上面的代码需要首先引用Microsoft PowerPoint 9.0 Type Library以及Microsoft Graph 9.0 Type Library
TechnoFantasy 2003-09-23
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Const sTemplate = "D:\WINNT\ShellNew\PWRPNT9.POT"
Const sPic = "C:\toptext.bmp"

Dim oApp As PowerPoint.Application
Dim oPres As PowerPoint.Presentation
Dim oSlide As PowerPoint.Slide
Dim bAssistantOn As Boolean

'Start Powerpoint and make its window visible but minimized.
Set oApp = New PowerPoint.Application
oApp.Visible = True
oApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized

'Create a new presentation based on the specified template.
Set oPres = oApp.Presentations.Open(sTemplate, , , True)

'Build Slide #1:
'Add text to the slide, change the font and insert/position a
'picture on the first slide.
Set oSlide = oPres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
With oSlide.Shapes.Item(1).TextFrame.TextRange
.Text = "My Sample Presentation"
.Font.Name = "Comic Sans MS"
.Font.Size = 48
End With
Call oSlide.Shapes.AddPicture(sPic, False, True, 150, 150, 500, 350)
Set oSlide = Nothing

'Build Slide #2:
'Add text to the slide title, format the text. Also add a chart to the
'slide and change the chart type to a 3D pie chart.
Set oSlide = oPres.Slides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
With oSlide.Shapes.Item(1).TextFrame.TextRange
.Text = "My Chart"
.Font.Name = "Comic Sans MS"
.Font.Size = 48
End With
Dim oChart As Graph.Chart
Set oChart = oSlide.Shapes.AddOLEObject(150, 150, 480, 320, _
"MSGraph.Chart.8").OLEFormat.Object
oChart.ChartType = Graph.XlChartType.xl3DPie
Set oChart = Nothing
Set oSlide = Nothing

'Build Slide #3:
'Add a text effect to the slide and apply shadows to the text effect.
Set oSlide = oPres.Slides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank)
oSlide.FollowMasterBackground = False
Dim oShape As PowerPoint.Shape
' Set oShape = oSlide.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect27, _
' "The End", "Impact", 96, False, False, 230, 200)
' oShape.Shadow.ForeColor.SchemeColor = PowerPoint.PpColorSchemeIndex.ppForeground
' oShape.Shadow.Visible = True
' oShape.Shadow.OffsetX = 3
' oShape.Shadow.OffsetY = 3
Set oShape = Nothing
Set oSlide = Nothing

'Modify the slide show transition settings for all 3 slides in
'the presentation.
Dim SlideIdx(3) As Integer
SlideIdx(0) = 1
SlideIdx(1) = 2
SlideIdx(2) = 3
With oPres.Slides.Range(SlideIdx).SlideShowTransition
.AdvanceOnTime = True
.AdvanceTime = 3
.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut
End With
Dim oSettings As PowerPoint.SlideShowSettings
Set oSettings = oPres.SlideShowSettings
oSettings.StartingSlide = 1
oSettings.EndingSlide = 3

'Prevent Office Assistant from displaying alert messages.
bAssistantOn = oApp.Assistant.On
oApp.Assistant.On = False

'Run the slide show and wait for the slide show to end.
oSettings.Run
Do While oApp.SlideShowWindows.Count >= 1
DoEvents
Loop
Set oSettings = Nothing

'Reenable Office Assisant, if it was on.
If bAssistantOn Then
oApp.Assistant.On = True
oApp.Assistant.Visible = False
End If

'Close the presentation without saving changes and quit PowerPoint.
oPres.Saved = True
oPres.Close
Set oPres = Nothing
oApp.Quit
Set oApp = Nothing
End Sub

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧