Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. vb.net pasting images into powerpoint

vb.net pasting images into powerpoint

Scheduled Pinned Locked Moved Visual Basic
csharpasp-netvisual-studiocom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    b rad311
    wrote on last edited by
    #1

    Hi everyone, I've written a visual basic gui program (using visual studio 2008 (.net)) and simply placed a button on it which, when pressed, activates the print screen of the active window and it then opens powerpoint, adds a slide, and it's then suppose to paste the image. A new slide gets created each time the button is pressed, and the image is supposed to be pasted to the new slide. The first iteration seems to work fine, but subsequent presses of the button yields the following error: "System.Runtime.InteropServices.COMException (0x80048240): Shapes (unknown member) : Invalid request. Clipboard is empty or contains data which may not be pasted here. at Microsoft.Office.Interop.PowerPoint.Shapes.Paste()" Other times the code goes an unlimited amount of button presses with no error, but when this occurs, the image is only updated every other button press. Any ideas?

    Imports Microsoft.Office.Interop
    Imports Microsoft.Office.Core
    Imports System.Drawing.Imaging

    Imports System.Runtime.InteropServices
    Imports System.Diagnostics

    Public Class Form1

    ' Start PowerPoint.
    Public ppApp As PowerPoint.Application
    
    ' Start counting number of times the take image button has been pressed by the user.
    Public num\_times\_pressed = 0
    
    ' Add a new presentation.
    Public ppPres As PowerPoint.Presentation
    

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    num_times_pressed = num_times_pressed + 1

        If num\_times\_pressed = 1 Then
            ppApp = CreateObject("Powerpoint.Application")
    
            ' Make it visible.
            ppApp.Visible = True
    
            ppPres = ppApp.Presentations.Add(MsoTriState.msoTrue)
            ppApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
    
            
    
        End If
    
        ' Add a new slide.
        Dim ppSlide1 As PowerPoint.Slide
        Dim SlideCount As Long
    
        SlideCount = ppPres.Slides.Count
        ppSlide1 = ppPres.Slides.Add(SlideCount + 1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank)
    
        Me.Hide()
        
        SendKeys.SendWait("%{Prtsc}")
        
        ppSlide1.Select()
        
    
        ppSlide1.Shapes.Paste()
        
    
        
        Me.Show()
            End Sub
    

    End Class

    Thanks!

    J 1 Reply Last reply
    0
    • B b rad311

      Hi everyone, I've written a visual basic gui program (using visual studio 2008 (.net)) and simply placed a button on it which, when pressed, activates the print screen of the active window and it then opens powerpoint, adds a slide, and it's then suppose to paste the image. A new slide gets created each time the button is pressed, and the image is supposed to be pasted to the new slide. The first iteration seems to work fine, but subsequent presses of the button yields the following error: "System.Runtime.InteropServices.COMException (0x80048240): Shapes (unknown member) : Invalid request. Clipboard is empty or contains data which may not be pasted here. at Microsoft.Office.Interop.PowerPoint.Shapes.Paste()" Other times the code goes an unlimited amount of button presses with no error, but when this occurs, the image is only updated every other button press. Any ideas?

      Imports Microsoft.Office.Interop
      Imports Microsoft.Office.Core
      Imports System.Drawing.Imaging

      Imports System.Runtime.InteropServices
      Imports System.Diagnostics

      Public Class Form1

      ' Start PowerPoint.
      Public ppApp As PowerPoint.Application
      
      ' Start counting number of times the take image button has been pressed by the user.
      Public num\_times\_pressed = 0
      
      ' Add a new presentation.
      Public ppPres As PowerPoint.Presentation
      

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      num_times_pressed = num_times_pressed + 1

          If num\_times\_pressed = 1 Then
              ppApp = CreateObject("Powerpoint.Application")
      
              ' Make it visible.
              ppApp.Visible = True
      
              ppPres = ppApp.Presentations.Add(MsoTriState.msoTrue)
              ppApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
      
              
      
          End If
      
          ' Add a new slide.
          Dim ppSlide1 As PowerPoint.Slide
          Dim SlideCount As Long
      
          SlideCount = ppPres.Slides.Count
          ppSlide1 = ppPres.Slides.Add(SlideCount + 1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank)
      
          Me.Hide()
          
          SendKeys.SendWait("%{Prtsc}")
          
          ppSlide1.Select()
          
      
          ppSlide1.Shapes.Paste()
          
      
          
          Me.Show()
              End Sub
      

      End Class

      Thanks!

      J Offline
      J Offline
      Johan Hakkesteegt
      wrote on last edited by
      #2

      If the error says Clipboard is empty, then most likely SendKeys.SendWait("%{Prtsc}") does not always correctly do what is supposed to. After the SendKeys bit, you could try checking the contents of the clip board first (My.Computer.Clipboard), to see if the print screen was actually performed, and there is a picture to be pasted. If there isn't you just perform the SendKeys again, until the clipboard contains a picture.

      My advice is free, and you may get what you paid for.

      B 1 Reply Last reply
      0
      • J Johan Hakkesteegt

        If the error says Clipboard is empty, then most likely SendKeys.SendWait("%{Prtsc}") does not always correctly do what is supposed to. After the SendKeys bit, you could try checking the contents of the clip board first (My.Computer.Clipboard), to see if the print screen was actually performed, and there is a picture to be pasted. If there isn't you just perform the SendKeys again, until the clipboard contains a picture.

        My advice is free, and you may get what you paid for.

        B Offline
        B Offline
        b rad311
        wrote on last edited by
        #3

        Hi John, Thanks for replying. The image is there because I can go to paint and paste it.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups