Results 1 to 7 of 7

Thread: [RESOLVED] PPT template open via Word

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Resolved [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

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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:
    1. Sub cmd_showpowerpoint_Click()
    2.     Dim ApPPT As Object, prsnPPT As Object
    3.    
    4.     On Error Resume Next
    5.    
    6.     '~~> Check if PowerPoint if already Open
    7.     Set ApPPT = GetObject(, "Powerpoint.application")
    8.        
    9.     If ApPPT Is Nothing Then
    10.         '~~> If no instance of PowerPoint is found then open one
    11.         Set ApPPT = CreateObject("Powerpoint.application")
    12.     End If
    13.    
    14.     On Error GoTo 0
    15.    
    16.     '~~> Display PowerPoint
    17.     ApPPT.Visible = True
    18.    
    19.     '~~> Open File
    20.     Set prsnPPT = ApPPT.Presentations.Open("c:\sid.pot")
    21. End Sub

    hope this helps...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    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
    Code:
    Untitled:=msoTrue
    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

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: PPT template open via Word

    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:
    1. '~~> IMPORTANT NOTE: Set Reference to the Microsoft Powerpoint Object library
    2.  
    3. Sub cmd_showpowerpoint_Click()
    4.     Dim ApPPT As PowerPoint.Application
    5.     Dim prsnPPT As PowerPoint.Presentation
    6.     Dim slidePPT As PowerPoint.Slide
    7.    
    8.     Set ApPPT = CreateObject("Powerpoint.Application")
    9.  
    10.     '~~> Make it visible.
    11.     ApPPT.Visible = True
    12.  
    13.     '~~> Add a new presentation.
    14.     Set prsnPPT = ApPPT.Presentations.Add(msoTrue)
    15.  
    16.     '~~> Add a new slide.
    17.     Set slidePPT = prsnPPT.Slides.Add(1, ppLayoutText)
    18.    
    19.     '~~> Apply Presentation
    20.     prsnPPT.ApplyTemplate Filename:="k:\zprecedents\dls.pot"
    21. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: PPT template open via Word

    Works brilliantly! many thanks again!

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] PPT template open via Word

    You are welcome
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: [RESOLVED] PPT template open via Word

    Bump!

    Great code for pp + word users
    Last edited by Kubull; Jun 25th, 2009 at 09:04 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width