Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-01-2014, 12:15 AM
tha_slughy tha_slughy is offline Inserting and formatting photos in word 2013 Windows 8 Inserting and formatting photos in word 2013 Office 2013
Novice
Inserting and formatting photos in word 2013
 
Join Date: Jul 2014
Posts: 3
tha_slughy is on a distinguished road
Exclamation Inserting and formatting photos in word 2013

Hello,



I have one problem, consisting of two issues. I use a lot of pictures in word reports, as to date in previous word versions I could easily process my pictures with a vba macro.

In order not to waste too much time I drag and drop the pictures in their required space, as an inlineshape and then resize these pictures to the required size.

As from word 2013 I noticed an oddity. The pictures which you drag and drop are sometimes inlineshape and sometimes not. As a result the macro not always works.

Moreover when the macro does work, it encounters different issues which I did not encounter in previous word versions.

To recap, the goal is to drop a photo (jpg) into a word document and be able to run a macro on it with a hotkey. The required actions are lock the aspect ratio, resize the width and fit the photo with a black solid border.

The current used macro is as follows:

Code:
Sub AfbeeldingImporteren()
'
' ResizeImage Macro
'
    Dim shape As InlineShape
    ' iterate all selected shapes
    For Each shape In Selection.InlineShapes
        ' remain aspect ratio
        shape.LockAspectRatio = msoTrue
        ' set width to 225 px
        newWidth = 225
        ' shape.Height = (newWidth / shape.Width) * shape.Height
        shape.Width = newWidth
        ' Add Borders
        Selection.InlineShapes(1).Line.Weight = 0.75
        Selection.InlineShapes(1).Line.DashStyle = msoLineSolid
        Selection.InlineShapes(1).Line.Visible = msoTrue
        Selection.InlineShapes(1).Line.ForeColor.RGB = RGB(0, 0, 0)
        
    Next

'
'
End Sub
All help resolving these two (probably connected) issues would be great!
Reply With Quote
  #2  
Old 07-03-2014, 11:39 PM
macropod's Avatar
macropod macropod is offline Inserting and formatting photos in word 2013 Windows 7 32bit Inserting and formatting photos in word 2013 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 picture insertion behaviour is primarily determined by your Word options. Under File|Options|Advanced>Cut, Copy & Paste>Insert/Paste pictures as, you can choose 'In-line with text' or one of the floating formats. Only the 'In-line with text' option will give you the behaviour desired for your macro. Even with that option, however, if you drag & drop an image that's in a 'floating' format from another document, or from another location in the same document, the format won't change to 'In-line with text' at the destination.

Try the following revision to your code. Do note that any Shape objects that get converted to InlineShapes are liable to change position to wherever they are anchored.

Code:
Sub AfbeeldingImporteren()
Dim i As Long
With Selection
  'Convert floating shapes to inline
  For i = .ShapeRange.Count To 1 Step -1
    .ShapeRange(i).ConvertToInlineShape
  Next
  'process all InlineShapes
  For i = 1 To .InlineShapes.Count
    With .InlineShapes(i)
      ' retain aspect ratio
      .LockAspectRatio = msoTrue
      ' set width to 225 px
      newWidth = 225
      .Width = newWidth
      ' Add Borders
      With .Line
        .Weight = 0.75
        .DashStyle = msoLineSolid
        .Visible = msoTrue
        .ForeColor.RGB = RGB(0, 0, 0)
      End With
    End With
  Next
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-09-2014, 03:32 AM
tha_slughy tha_slughy is offline Inserting and formatting photos in word 2013 Windows 8 Inserting and formatting photos in word 2013 Office 2013
Novice
Inserting and formatting photos in word 2013
 
Join Date: Jul 2014
Posts: 3
tha_slughy is on a distinguished road
Default

Dear Macropod,

thanks for your reply.

I get a compiling error on line " With InlineShapes(i) "

'sub of function not defined'.

I tried making it into .InlineShapes(i), however this brings on a whole new set of errors.

Brgds,
Reply With Quote
  #4  
Old 07-09-2014, 05:06 AM
macropod's Avatar
macropod macropod is offline Inserting and formatting photos in word 2013 Windows 7 32bit Inserting and formatting photos in word 2013 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 should be using 'With .InlineShapes(i)'. I have no idea what you mean by "this brings on a whole new set of errors".
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-13-2014, 09:35 AM
tha_slughy tha_slughy is offline Inserting and formatting photos in word 2013 Windows 8 Inserting and formatting photos in word 2013 Office 2013
Novice
Inserting and formatting photos in word 2013
 
Join Date: Jul 2014
Posts: 3
tha_slughy is on a distinguished road
Default

using

Code:
 With .InlineShapes(i)
makes me receive following error:

Code:
Runtime error '4198'
Command Failed
And going to debugging it highlights line

Code:
For i = .ShapeRange.Count To 1 Step -1
Brgds,

Tha
Reply With Quote
  #6  
Old 07-13-2014, 04:39 PM
macropod's Avatar
macropod macropod is offline Inserting and formatting photos in word 2013 Windows 7 32bit Inserting and formatting photos in word 2013 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

That suggests there may be a fault with your Office installation. Try repairing it (via Programs & Features > Microsoft Office > Change in the Windows Control Panel).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
formatting, inlinestyles, photos

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting and formatting photos in word 2013 Help formatting Pictures inside a Text Box in Word 2013 jstumbo87 Word 2 01-29-2014 12:07 PM
Inserting and formatting photos in word 2013 Word 2013 vs Word 2010 formatting issue? rhoyt Word 1 12-07-2013 09:40 AM
TOC Page number Formatting - Word 2013 Adam83 Word 6 11-01-2013 12:00 PM
Inserting photos casatropical Word 1 01-18-2012 10:30 AM
Inserting and formatting photos in word 2013 Inserting / formatting multiple photos into Word doc. Jeremiahts Drawing and Graphics 1 03-23-2011 07:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:34 PM.


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