Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-25-2014, 06:59 PM
Duvdev Duvdev is offline How to use VBA code to format a screenshot in memory (from clipboard)? Windows 7 64bit How to use VBA code to format a screenshot in memory (from clipboard)? Office 2010 64bit
Novice
How to use VBA code to format a screenshot in memory (from clipboard)?
 
Join Date: Mar 2014
Posts: 4
Duvdev is on a distinguished road
Default How to use VBA code to format a screenshot in memory (from clipboard)?

Hello,



I am trying to write several different macros for working with images including cropping, resizing, formatting, etc. I have most code figured out but have one seemingly simple issue. My macros execute perfectly fine as long as I am working with a screenshot or any image already pasted into Word. However, I am trying to figure out how to apply the VBA macro code to a window that I screenshot.

It makes sense to me that either the code would operate directly on the screenshot and paste into Word, or would paste into Word then select the screenshot and run the remainder of the macro code after the fact. I currently use the ‘Selection.Paste’ command to paste screenshots directly into word then force the cursor to “walk” backwards to highlight the screenshot. Sadly this isn’t a great option because my macros mess up other formatting when pasting directly into a table. All issues should be avoided if I can reformat the screenshots then pasting at the very end.

If anyone has any ideas of how to either operate directly on a screenshot in memory, or to force Word to paste and image without unselecting (normal Word paste command pastes the screenshot followed by moving the cursor one space meaning the screenshot is no longer selected).

Seems like this would be one simple line of code or special paste option but I cannot figure it out for the life of me.

Thank you for your time
Reply With Quote
  #2  
Old 03-26-2014, 12:03 AM
macropod's Avatar
macropod macropod is offline How to use VBA code to format a screenshot in memory (from clipboard)? Windows 7 32bit How to use VBA code to format a screenshot in memory (from clipboard)? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The short answer is: you can't. Editing an inserted image isn't at all difficult, though. For example, without knowing whether you're pasting in-line or wrapped, the following code will work with whatever you paste. Simply adjust the parameters to suit.
Code:
Sub Demo()
Dim Rng As Range
Set Rng = Selection.Range
With Rng
  .Paste
  If .ShapeRange.Count = 1 Then
    With .ShapeRange(1)
      .LockAspectRatio = msoTrue
      .Width = InchesToPoints(4)
      With .PictureFormat
        .CropBottom = InchesToPoints(0.75)
        .CropTop = InchesToPoints(0.75)
        .CropLeft = InchesToPoints(1)
        .CropRight = InchesToPoints(1)
      End With
    End With
  ElseIf .InlineShapes.Count = 1 Then
    With .InlineShapes(1)
      .LockAspectRatio = msoTrue
      .Width = InchesToPoints(4)
      With .PictureFormat
        .CropBottom = InchesToPoints(0.75)
        .CropTop = InchesToPoints(0.75)
        .CropLeft = InchesToPoints(1)
        .CropRight = InchesToPoints(1)
      End With
    End With
  End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-26-2014, 05:09 PM
Duvdev Duvdev is offline How to use VBA code to format a screenshot in memory (from clipboard)? Windows 7 64bit How to use VBA code to format a screenshot in memory (from clipboard)? Office 2010 64bit
Novice
How to use VBA code to format a screenshot in memory (from clipboard)?
 
Join Date: Mar 2014
Posts: 4
Duvdev is on a distinguished road
Default Thank you

Thank you Macropod,

Extremely useful and well written code!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Best Way to Decolor a Screenshot SQLUSA Word 1 07-15-2012 09:08 PM
How to use VBA code to format a screenshot in memory (from clipboard)? Code to Create & Format Document Sections sleake Word 6 04-26-2012 04:14 AM
Change format of date when using Now function in VB code Bondai Excel Programming 2 03-02-2012 05:09 PM
How to use VBA code to format a screenshot in memory (from clipboard)? How to type into a screenshot in word? greenwall Word 2 11-24-2011 02:14 PM
Cropping an screenshot ( screen shot pasted into word 2007. aligahk06 Word 1 10-07-2009 07:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft