Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-23-2017, 12:09 AM
rueffy rueffy is offline Creating an Image Formatting Macro Windows 10 Creating an Image Formatting Macro Office 2013
Novice
Creating an Image Formatting Macro
 
Join Date: Mar 2017
Posts: 5
rueffy is on a distinguished road
Default Creating an Image Formatting Macro

Hi,

I'd like to create what I believe to be a fairly complex macro in word. I've tried doing it manually using the Record Macro function but given it involves images it doesn't appear to be working. The basic steps are:

1) Convert the image from whatever format it is into a JPEG or any other image format that is suitable for compression (to do this manually I simply cut the image and then Special Paste and select the appropriate format). I am usually pasting in from the snipping tool which produces and output format unsuitable for compression.

2) Compress the image so that its size dimensions are reduced.

3) Apply a solid border with 2 1/4 point thickness.



Can anyone offer a solution? Thanks in advance.

Jay
Reply With Quote
  #2  
Old 08-23-2017, 01:44 AM
macropod's Avatar
macropod macropod is offline Creating an Image Formatting Macro Windows 7 64bit Creating an Image Formatting Macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

You could use something along the lines of:
Code:
Sub Demo()
Dim t As Single, l As Single, tRel As Single, lRel As Single
With Selection
  If .InlineShapes.Count = 1 Then
    .InlineShapes(1).Range.Cut
    .PasteSpecial DataType:=15
    .End = .End + 1
    With .InlineShapes(1).Borders
      .Enable = True
      .OutsideLineStyle = wdLineStyleSingle
      .OutsideLineWidth = wdLineWidth225pt
      .OutsideColorIndex = wdBlack
    End With
  ElseIf .ShapeRange.Count = 1 Then
    With .ShapeRange(1)
      tRel = .TopRelative
      t = .Top
      lRel = .LeftRelative
      l = .Left
      .Anchor.Cut
    End With
    .PasteSpecial DataType:=15
    .End = .End + 1
    With .InlineShapes(1).Borders
      .Enable = True
      .OutsideLineStyle = wdLineStyleSingle
      .OutsideLineWidth = wdLineWidth225pt
      .OutsideColorIndex = wdBlack
    End With
    .InlineShapes(1).ConvertToShape
    With .ShapeRange(1)
      .TopRelative = tRel
      .Top = t
      .LeftRelative = lRel
      .Left = l
    End With
  End If
End With
End Sub
As for your compression requirements, though, your "so that its size dimensions are reduced" is ambiguous and there's no VBA access to Word's image compression, per se.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-23-2017, 02:13 AM
rueffy rueffy is offline Creating an Image Formatting Macro Windows 10 Creating an Image Formatting Macro Office 2013
Novice
Creating an Image Formatting Macro
 
Join Date: Mar 2017
Posts: 5
rueffy is on a distinguished road
Default

Hey macropod,

Thanks so much. With regard to size dimensions, I will be resizing the images manually to the size I want them before I execute the Macro. I'll then use the Macro to lock the dimensions is place using compression. If I paste the images to another application outside of word without compression the image will return back to its original dimensions.

Having said that, will the Macro as you've posted it still function correctly?

Thanks,
Jay
Reply With Quote
  #4  
Old 08-23-2017, 04:23 AM
macropod's Avatar
macropod macropod is offline Creating an Image Formatting Macro Windows 7 64bit Creating an Image Formatting Macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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 macro I posted simply copies the image then pastes it back into the document as a jpg with the same dimensions it already had - then applies the desired border. It makes no difference whether you compress the image before, or after, running the macro.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 08-23-2017, 07:52 PM
rueffy rueffy is offline Creating an Image Formatting Macro Windows 10 Creating an Image Formatting Macro Office 2013
Novice
Creating an Image Formatting Macro
 
Join Date: Mar 2017
Posts: 5
rueffy is on a distinguished road
Default

Thanks again macropod,

It works well, I'm very happy with it. I simply created a new toolbar section with the macro shortcut and the compress picture shortcut so its all fairly self-contained and efficient.

Can I ask one more favour? Can you replicate the same function but without the image bordering? I've since realised that some images I would like a border, and some I wouldn't. I tried to edit the macro myself but I had problems. When I tried to change the name from Demo to something else to distinguish it, it didn't seem to like it.

Thanks,
Jay.
Reply With Quote
  #6  
Old 08-23-2017, 08:16 PM
macropod's Avatar
macropod macropod is offline Creating an Image Formatting Macro Windows 7 64bit Creating an Image Formatting Macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

All you need for that is to make a copy of the macro & change 'Demo' on the copy to something else, then delete the two 'With .InlineShapes(1).Borders ... End With' blocks.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 08-23-2017, 08:32 PM
rueffy rueffy is offline Creating an Image Formatting Macro Windows 10 Creating an Image Formatting Macro Office 2013
Novice
Creating an Image Formatting Macro
 
Join Date: Mar 2017
Posts: 5
rueffy is on a distinguished road
Default

Worked a treat.

Once again thanks for your support.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
bizarre problem with page background image when creating pdf dbltapp Word 0 06-04-2015 04:57 PM
URGENT!!! Powerpoint Image Formatting and Positioning Macro mertulufi PowerPoint 5 12-20-2011 10:14 AM
creating border to image without surrounding text gib65 Drawing and Graphics 5 08-15-2011 09:17 AM
Creating an Image Formatting Macro Problem creating link to image file leftylee PowerPoint 1 04-14-2010 05:49 AM
Creating An Image Contact Sheet Template skoz55 Drawing and Graphics 0 08-06-2009 10:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:24 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