[RESOLVED] PPT template open via Word
Hey all,
I've created a PowerPoint template (.pot) file for my clients to use if they need to create a corporate presentation. Here we use MS Word as a main conduit to all our word (.dot) templates and alike, I'm trying to add my new template with the others on a form in Word but to no success, I'm created the below code but it keep throwing a wobbly "RT Error 91 - ob variable or with block variable not set"
Any Help would be greatly appreciated
Code:
Sub cmd_showpowerpoint_Click()
Dim ppt As Object
Dim MyappID As String
ppt.Presentations.Open FileName:="k:\zprecedents\dls.pot", Untitled:=msoTrue
MyappID = Shell("C:\Program Files\Microsoft Office\Office\POWERPNT.EXE", 1) 'Run Microsoft Powerpoint
FileSystem.ChDir "K:\"
Set ppt = CreateObject("powerpoint.application")
Set ppt = Nothing
End Sub
Re: PPT template open via Word
The problem with your code is you are trying to use the object before creating it....
Here is a basic way, you can open a Powerpoint file using late binding...
vb Code:
Sub cmd_showpowerpoint_Click()
Dim ApPPT As Object, prsnPPT As Object
On Error Resume Next
'~~> Check if PowerPoint if already Open
Set ApPPT = GetObject(, "Powerpoint.application")
If ApPPT Is Nothing Then
'~~> If no instance of PowerPoint is found then open one
Set ApPPT = CreateObject("Powerpoint.application")
End If
On Error GoTo 0
'~~> Display PowerPoint
ApPPT.Visible = True
'~~> Open File
Set prsnPPT = ApPPT.Presentations.Open("c:\sid.pot")
End Sub
hope this helps...
Re: PPT template open via Word
Yeah Sorry, I posted my code in the wrong order do'h! the original is below.
I tried your code which works well, but it opens it up directly into the .pot file, I need the template to open as a new .ppt which I thought my code would.
I suppose all I'd need to do is add to yours is at the open file bit?
Code:
Sub cmd_showpowerpoint_Click()
MyappID = Shell("C:\Program Files\Microsoft Office\Office\POWERPNT.EXE", 1) 'Run Microsoft Powerpoint
ppt.Presentations.Open FileName:="k:\zprecedents\dls.pot", Untitled:=msoTrue
FileSystem.ChDir "K:\"
Set ppt = CreateObject("powerpoint.application")
Set ppt = Nothing
End Sub
Re: PPT template open via Word
Quote:
I need the template to open as a new .ppt which I thought my code would.
Oh Ok, Is this what you Want? Remember to Set Reference to the Microsoft Powerpoint Object library
vb Code:
'~~> IMPORTANT NOTE: Set Reference to the Microsoft Powerpoint Object library
Sub cmd_showpowerpoint_Click()
Dim ApPPT As PowerPoint.Application
Dim prsnPPT As PowerPoint.Presentation
Dim slidePPT As PowerPoint.Slide
Set ApPPT = CreateObject("Powerpoint.Application")
'~~> Make it visible.
ApPPT.Visible = True
'~~> Add a new presentation.
Set prsnPPT = ApPPT.Presentations.Add(msoTrue)
'~~> Add a new slide.
Set slidePPT = prsnPPT.Slides.Add(1, ppLayoutText)
'~~> Apply Presentation
prsnPPT.ApplyTemplate Filename:="k:\zprecedents\dls.pot"
End Sub
Re: PPT template open via Word
Works brilliantly! many thanks again!
Re: [RESOLVED] PPT template open via Word
Re: [RESOLVED] PPT template open via Word
Bump!
Great code for pp + word users