Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-20-2020, 05:44 AM
ksor ksor is offline Formatting picture Windows 10 Formatting picture Office 2016
Advanced Beginner
Formatting picture
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 38
ksor is on a distinguished road
Default Formatting picture

I use this code to format a picture - just a frame around it

Sub FormatPicture()
'
' FormatPicture Makro
'


With Selection
If .InlineShapes.Count <> 1 Then Exit Sub
With .InlineShapes(1)
With .Borders
.Enable = True
.OutsideLineWidth = wdLineWidth300pt <<<<<<<<<<<<<<<< crashes here when stepping through ???
.OutsideLineStyle = wdLineStyleSingle
.OutsideColorIndex = wdBlack
End With
End With
End With
End Sub

but it ONLY works if the picture is "in line with text" !

How can I change it to work on "flowting pictures too ?


EDIT: Too I noticed that the machines freezes/crashes at the marked line when stepping through the code - why

Last edited by ksor; 11-20-2020 at 09:02 AM.
Reply With Quote
  #2  
Old 11-20-2020, 01:06 PM
gmaxey gmaxey is offline Formatting picture Windows 10 Formatting picture Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,133
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

Because floating objects are not inlineshapes.


Code:
Sub AddBorderToShape()
Dim oShp As Shape
  On Error Resume Next
  Set oShp = Selection.ShapeRange(1)
  MsgBox Err.Number
  If Err.Number <> 0 Then Exit Sub
  With oShp
    .Line.ForeColor.RGB = RGB(0, 0, 0)
    .Line.Weight = 4
    .Line.DashStyle = msoLineSolid
  End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-20-2020, 01:42 PM
ksor ksor is offline Formatting picture Windows 10 Formatting picture Office 2016
Advanced Beginner
Formatting picture
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 38
ksor is on a distinguished road
Default

I don't know it your answer "Because floating objects are not inlineshapes." should
imply that your code would work - it doesn't - it gives Err.Number = 5


And still the machine freezes when stepping through the code


And my Q was: "How can I change it to work on "flowting pictures too ?"
Reply With Quote
  #4  
Old 11-20-2020, 01:48 PM
gmaxey gmaxey is offline Formatting picture Windows 10 Formatting picture Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,133
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

If you get an error number 5 it is because you don't have a floating shape selected.


Sometimes working with inline shapes and shape objects, that happens.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 11-20-2020, 01:52 PM
gmaxey gmaxey is offline Formatting picture Windows 10 Formatting picture Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,133
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

See video for example
Attached Files
File Type: zip Video.zip (334.3 KB, 9 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 11-20-2020, 02:02 PM
ksor ksor is offline Formatting picture Windows 10 Formatting picture Office 2016
Advanced Beginner
Formatting picture
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 38
ksor is on a distinguished road
Default

You're just repeating a not working solution with the comment "it happens sometimes !"


Here it happens every time I try to put a solid frame on my inline or flouting pictures.


Reply With Quote
  #7  
Old 11-20-2020, 04:41 PM
gmaxey gmaxey is offline Formatting picture Windows 10 Formatting picture Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,133
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

Instead of grumbling about what I've posted why don't you try to better explain your problem. If you have a picture in a document that is in front of text, behind text, tight, square, etc. Then it is a "Shape" object (not an Inlineshape object). If you select the shape then the msgbox in the code I posted will return 0 instead of 5 and work as the video I posted proves.


As for the "freeze" okay it happens all the time when you have a shape or inlineshaped selected. Is that better??
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #8  
Old 11-20-2020, 04:50 PM
gmaxey gmaxey is offline Formatting picture Windows 10 Formatting picture Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,133
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

Step through this version of your original code. It won't hang because the inlineshape is no longer selected:


Code:
Sub Whine1()
Dim oILS As InlineShape
  With Selection
    If .InlineShapes.Count <> 1 Then Exit Sub
    Set oILS = .InlineShapes(1)
    .Collapse wdCollapseEnd
  End With
  With oILS.Borders
    .Enable = True
    .OutsideLineWidth = wdLineWidth300pt
    .OutsideLineStyle = wdLineStyleSingle
    .OutsideColorIndex = wdBlack
  End With
End Sub

and this, it will format all the inlineshapes and shapes in the main text storyrange of the document.


Code:
Sub WhineII()
Dim oILS As InlineShape
Dim oShp As Shape

  For Each oILS In ActiveDocument.InlineShapes
    With oILS.Borders
      .Enable = True
      .OutsideLineWidth = wdLineWidth300pt
      .OutsideLineStyle = wdLineStyleSingle
      .OutsideColorIndex = wdBlack
    End With
  Next oILS
  For Each oShp In ActiveDocument.Shapes
    With oShp
       .Line.ForeColor.RGB = RGB(0, 0, 0)
       .Line.Weight = 4
       .Line.DashStyle = msoLineSolid
    End With
  Next
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 11-20-2020, 11:20 PM
ksor ksor is offline Formatting picture Windows 10 Formatting picture Office 2016
Advanced Beginner
Formatting picture
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 38
ksor is on a distinguished road
Default

Grumbling


You should just read my original Q:


"How can I change it to work on "flowting pictures too ?"


and now you did ... and TOO made an exelent solution - THX !
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting picture Inserting and formatting a picture BLUEPUPIL Word VBA 2 04-28-2019 03:14 PM
Formatting picture Picture formatting. voyagerone Drawing and Graphics 3 05-31-2016 09:55 PM
Picture Formatting Problem thowes2 Word 1 04-24-2013 05:24 PM
Formatting picture Picture Formatting Issues mayj Word 1 04-02-2013 03:09 AM
Formatting picture insert object or picture, strange formatting layout qwertyjjj Word 5 01-10-2013 09:49 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 09:54 AM.


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