Results 1 to 8 of 8

Thread: paste screen shot from clipboard into PowerPoint

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    4

    Question paste screen shot from clipboard into PowerPoint

    Here's what I'm trying to do. I have published an internet map site on our intranet where local users can create their own custom maps.

    I want to create a button on that webpage (using a combination VB and ASP) that when clicked will take a snap shot of the active window (the map they have created) and paste it to their clipboard. Then I want to launch PowerPoint on their workstation, add a blank slide, and paste the snap shot from their clipboard onto that blank slide.

    Is this possible? I have some code, but I would like someone with more VB experience than me to check it out. I have tested it on my computer by sticking the code behind a command button on a user form in MS Word, and it runs fine up until the last 3 or 4 lines of code (the paste from clipboard part). I get a run-time error '424': object required error on the line: Set Picture = Clipboard.GetData(vbCFBitmap).

    Any advice? Here is the code:

    VB Code:
    1. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
    2. ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    3.  
    4. Private Const VK_SNAPSHOT = &H2C
    5.  
    6. ' Get the Active Window
    7. keybd_event vbKeySnapshot, 1, 0, 0
    8.  
    9. Dim ppApp
    10. Set ppApp = CreateObject("Powerpoint.Application")
    11. ' Make it visible.
    12. ppApp.Visible = True
    13.  
    14. ' Add a new presentation.
    15. Dim ppPres
    16. Set ppPres = ppApp.Presentations.Add(msoTrue)
    17.  
    18. ' Add a new slide.
    19. Dim ppSlide1
    20. Set ppSlide1 = ppPres.Slides.Add(1, 1)
    21.  
    22. ' Add the image.
    23. Dim Picture
    24. Set Picture = Clipboard.GetData(vbCFBitmap)
    25. ppSlide1.Shapes.AddPicture (Picture)
    Last edited by GIO; Sep 16th, 2004 at 07:32 AM.

  2. #2
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    I dont see any code (Clipboard.SetData) to put the image on the clipboard in the first place ... that is probably why you get the error.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    4
    The fourth line from the top

    ' Get the Active Window
    keybd_event vbKeySnapshot, 1, 0, 0

    is where the screen shot is taken and sent to the clipboard.

  4. #4
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Originally posted by GIO
    The fourth line from the top

    ' Get the Active Window
    keybd_event vbKeySnapshot, 1, 0, 0

    is where the screen shot is taken and sent to the clipboard.
    should

    keybd_event vbKeySnapshot, 1, 0, 0

    be

    keybd_event VK_SNAPSHOT , 1, 0, 0

    ??

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    This line is generating an error because the clipboard object
    is trying to be set to the Picture object (Defined as ???). You can't use the
    clipboard object this way. You need to define a IPictureDisp
    object to hold the clipboard data, add that as the picture.

    VB Code:
    1. Dim iPic As IPictureDisp
    2. Set iPic = Clipboard.GetData(vbCFBitmap)
    3. ppSlide1.Shapes.AddPicture (iPic)
    If you right click the vbforums logo picture and click Copy, and run
    this code below, it will paste the vb image on to the form.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim iPic As IPictureDisp
    5.     Set iPic = Clipboard.GetData(vbCFBitmap)
    6.     Form1.Picture = iPic
    7. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    4
    Thanks to everyone for replying. I changed my code to the following:
    VB Code:
    1. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
    2. ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    3.  
    4. Private Const VK_SNAPSHOT = &H2C
    5.  
    6. ' Get the Active Window
    7. keybd_event vbKeySnapshot, 1, 0, 0
    8.  
    9. Dim ppApp
    10. Set ppApp = CreateObject("Powerpoint.Application")
    11. ' Make it visible.
    12. ppApp.Visible = True
    13.  
    14. ' Add a new presentation.
    15. Dim ppPres
    16. Set ppPres = ppApp.Presentations.Add(msoTrue)
    17.  
    18. ' Add a new slide.
    19. Dim ppSlide1
    20. Set ppSlide1 = ppPres.Slides.Add(1, 1)
    21.  
    22. ' Add the image.
    23. Dim iPic As IPictureDisp
    24. Set iPic = Clipboard.GetData(vbCFBitmap)
    25. ppSlide1.Shapes.AddPicture (iPic)
    However, the paste function still doesn't work once PowerPoint is open, and I am now getting a Run-time error '424': Object Required on the line:

    Set iPic = Clipboard.GetData(vbCFBitmap)

    I'm open to all suggestions.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Well the code should work, it works for me?
    IPictureDisp does show in your object browser?

    Muddy:
    (vbKeySnapshot = 44) = (VK_SNAPSHOT = 2C)


    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    4
    Yes, your code works, but when I modify it to fit my app something is causing it not to paste the snapshot into PowerPoint. Can you try my code from the post dated 09-16-2004 11:25 AM? I just want a snapshot of the active screen to be pasted on a blank slide in PwerPoint.

    I've been putting it behing a Command Button (CommandButton1) on a User Form in MS Word to test it. Maybe you'll get a better idea of what I'm trying to do, and see the error I'm getting if you try that.

    I can click the paste button to drop the image from the clipboard once PowerPoint opens, but that's not what I want the user to have to do.
    Last edited by GIO; Sep 16th, 2004 at 06:25 PM.

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