Consulting

Results 1 to 14 of 14

Thread: Solved: picture style word 2010

  1. #1
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location

    Solved: picture style word 2010

    Dear All,

    I want to VBA Macros code inserted for Picture Style; here as backgrounds I have different pictures in table column, which I autofited by below macros.

    But I want picture format should be apply for all, "Rounded diagonal corner , White".

    How I can modified below code.

    Picture Style:- http://blogs.office.com/b/microsoft-...000-words.aspx


    [vba]

    Sub Demo() Dim iShp As InlineShape
    With
    ActiveDocument For Each iShp In InlineShapes If iShp.Range.Information(wdWithInTable) = True Then With iShp .LockAspectRatio = True .Width = .Range.Cells(1).Column.Width End With End If Next End With End Sub

    [/vba]

    Regards,
    RL

  2. #2
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location
    Any reply to thread...

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Have you tried recording a macro. What have you tried?

  4. #4
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location
    I tried, but no succeed..
    Reason, macro does not show any code when I change style of current picture.

  5. #5
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location
    Anyone has suggestions....

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    Sometims the MS developers use a little magic dust and as far as I can tell there isn't a way to directly set the named picture styles from VBA or easily capture all the attributes of a given picture. All I can suggest is that could insert and format a picture with a style and one without and then view and compare the properties of each in the VBE locals or watch window.

    There are a lot of properties, and a rounded corners doesn't jump out, but you can mimic many of the style attritbutes by matching attributes like "Borders, Fill, Glow, Picture Format, Reflection, Shadow, SoftEdge, and Offsets. Several of these properties have children properties of their own so if solution is there is may be buried several layers deep.

    For example, this mimics the "simple frame black" style.

    [VBA]With ThisDocument.InlineShapes(1)
    .Borders.OutsideLineStyle = wdLineStyleSingle
    .Borders.OutsideLineWidth = wdLineWidth300pt
    With .Shadow
    .Blur = 4
    .OffsetX = 2.12132
    .OffsetY = 2.12132
    .Style = msoShadowStyleOuterShadow
    .Transparency = 0.57
    .Visible = msoTrue
    End With
    End With
    [/VBA]

    Good luck and if you find the right mixture of these properties, post back and let us know.
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location
    Thanks gmaxey,

    I applied the given code but no effect any to change Picture Style in Document.

    Can you suggest further!!@!!

  8. #8
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    Like I said, unless you can compare and match every atttribute with the formatted picture and apply it to a new picture and get the desired result, then I don't know if it can be done. I looked briefly and didn't see anything in the available attributes that would apply the two rounded corners.
    Greg

    Visit my website: http://gregmaxey.com

  9. #9
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location
    Dear Greg,

    Definitely, I am searching if found will be posted here.

    Regards,
    RL

  10. #10
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    Ok, the key seems to be first converting the inline shape to a shape and apply a autoshape format to the frame:

    [VBA]Option Explicit
    Public Sub AddSnippedDiagonalCornerWhite()
    Dim WdInlineShape As InlineShape
    Dim WdShape As Shape
    Set WdInlineShape = ActiveDocument.InlineShapes(1)

    'Convert to shape. I could be wrong, but this seems to be the only way to get the snipped corners.
    Set WdShape = WdInlineShape.ConvertToShape
    WdShape.PictureFormat.ColorType = msoPictureAutomatic
    'Snip the corners
    WdShape.AutoShapeType = msoShapeSnip2DiagRectangle
    WdShape.Fill.Solid
    With WdShape.Line
    .Weight = 7
    .Style = msoLineSingle
    .ForeColor.RGB = 16777215
    End With
    With WdShape.Shadow
    .Style = msoShadowStyleOuterShadow
    .Blur = 7
    .Transparency = 0.55
    .Size = 100
    End With
    With WdShape.ThreeD
    .BevelBottomType = msoBevelNone
    .BevelBottomDepth = 0
    .BevelBottomInset = 0
    .BevelTopType = msoBevelCircle
    .BevelTopDepth = 1.5
    .BevelTopInset = 2
    .FieldOfView = 45
    .Perspective = msoFalse
    .PresetMaterial = msoMaterialWarmMatte
    .PresetLighting = msoLightRigTwoPoint
    .LightAngle = 120
    End With
    WdShape.ConvertToInlineShape
    End Sub
    Public Sub AddRoundedDiagonalCornerWhite()
    Dim WdInlineShape As InlineShape
    Dim WdShape As Shape
    Set WdInlineShape = ActiveDocument.InlineShapes(1)

    'Convert to shape. I could be wrong, but this seems to be the only way to get the rounded corners.
    Set WdShape = WdInlineShape.ConvertToShape
    WdShape.PictureFormat.ColorType = msoPictureAutomatic
    'Snip the corners
    WdShape.AutoShapeType = msoShapeRound2DiagRectangle
    WdShape.Fill.Solid
    With WdShape.Line
    .Weight = 7
    .Style = msoLineSingle
    .ForeColor.RGB = 16777215
    End With
    With WdShape.Shadow
    .Style = msoShadowStyleOuterShadow
    .Blur = 7
    .Transparency = 0.55
    .Size = 100
    End With
    With WdShape.ThreeD
    .BevelBottomType = msoBevelNone
    .BevelBottomDepth = 0
    .BevelBottomInset = 0
    .BevelTopType = msoBevelCircle
    .BevelTopDepth = 1.5
    .BevelTopInset = 2
    .FieldOfView = 45
    .Perspective = msoFalse
    .PresetMaterial = msoMaterialWarmMatte
    .PresetLighting = msoLightRigTwoPoint
    .LightAngle = 120
    End With
    WdShape.ConvertToInlineShape
    End Sub
    [/VBA]
    Greg

    Visit my website: http://gregmaxey.com

  11. #11
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    Ok, back to your original post. I am not sure that the results here "exactly" replicate the preset style, but it appeaars to be very close:

    [VBA]Sub Demo()
    Dim iShp As InlineShape
    With ActiveDocument
    For Each iShp In .InlineShapes
    If iShp.Range.Information(wdWithInTable) = True Then
    With iShp
    .LockAspectRatio = True
    .Width = .Range.Cells(1).Column.Width - 50 'You might have to tinker with the width a bit.
    End With
    AddRoundedDiagonalCornerWhite iShp
    End If
    Next
    End With
    End Sub
    Public Sub AddRoundedDiagonalCornerWhite(ByRef oILSPassed As InlineShape)
    Dim WdShape As Shape
    'Convert to shape. I could be wrong, but this seems to be the only way to get the rounded corners.
    Set WdShape = oILSPassed.ConvertToShape
    WdShape.PictureFormat.ColorType = msoPictureAutomatic
    'Rounded the corners
    WdShape.AutoShapeType = msoShapeRound2DiagRectangle
    'Set other attributes to match preformatted picture.
    WdShape.Fill.Solid
    With WdShape.Line
    .Weight = 7
    .Style = msoLineSingle
    .ForeColor.RGB = 16777215
    End With
    With WdShape.Shadow
    .Style = msoShadowStyleOuterShadow
    .Blur = 7
    .Transparency = 0.55
    .Size = 100
    End With
    With WdShape.ThreeD
    .BevelBottomType = msoBevelNone
    .BevelBottomDepth = 0
    .BevelBottomInset = 0
    .BevelTopType = msoBevelCircle
    .BevelTopDepth = 1.5
    .BevelTopInset = 2
    .FieldOfView = 45
    .Perspective = msoFalse
    .PresetMaterial = msoMaterialWarmMatte
    .PresetLighting = msoLightRigTwoPoint
    .LightAngle = 120
    End With
    WdShape.ConvertToInlineShape
    End Sub
    [/VBA]
    Greg

    Visit my website: http://gregmaxey.com

  12. #12
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location
    Dear Greg,

    You are Fabulous, It worked exact same which I am looking for...

    Appreciated your efforts, time and great work to solve this thread.

    Thank You Very Much

    Regards,

    Rahul

  13. #13
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    Rahul,

    Actually the format I gave you wasn't as close as it could be. I was focused on the "snipped" edge rather than the rounded edge. So a closer match for the rounded edge is:

    [VBA]Public Sub AddRoundedDiagonalCornerWhite(ByRef oILSPassed As InlineShape)
    Dim WdShape As Shape
    'Convert to shape. I could be wrong, but this seems to be the only way to get the rounded corners.
    Set WdShape = oILSPassed.ConvertToShape
    WdShape.PictureFormat.ColorType = msoPictureAutomatic
    'Rounded the corners
    WdShape.AutoShapeType = msoShapeRound2DiagRectangle
    'Set other attributes to match preformatted picture.
    With WdShape.Line
    .Weight = 7
    .Style = msoLineSingle
    .ForeColor.RGB = 16777215
    End With
    With WdShape.Shadow
    .Style = msoShadowStyleOuterShadow
    .Blur = 20
    .Transparency = 0.57
    .Size = 100
    End With
    'Maybe someone knows how to select the image and apply SendKeys or some other method _
    to apply a "Flat" cap attibute and a "Mitered" join attribute to the line style.
    'WdShape.Select
    WdShape.ConvertToInlineShape
    End Sub[/VBA]

    Note that in the formatting dialog that there are two attributes for the "Line Style"

    Cap type and Join Type. When you insert a picture and add a border line the join type defaults to "Round." There doesn't appear to be any access in the object module (at least I couldn't find it) to set this to "Mitered" which is the join type set in the predefined style. Accordingly, you will notice that the square corners of the white border aren't actually squard but rounded slightly.

    I suppose that you could also select the picture and using SendKeys or something manipulte the dialog to set this attribute but that is an area that causes me to cuss worse than the sailor I once was, so I avoid it.

    Good luck.
    Greg

    Visit my website: http://gregmaxey.com

  14. #14
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    Rahul,

    Here is another method that relies on you manually applying the desired style to the first image. It basically selects and copies the formatting of the first image and then pastes that formatting to all subsequent images.


    [VBA]Sub DemoII()
    Dim iShp As InlineShape
    Dim i As Long
    i = 0
    With ActiveDocument
    For Each iShp In .InlineShapes

    If iShp.Range.Information(wdWithInTable) = True Then
    i = i + 1
    If i = 1 Then
    iShp.Select
    Selection.CopyFormat
    End If
    With iShp
    .LockAspectRatio = True
    .Width = .Range.Cells(1).PreferredWidth - 50 'You might have to tinker with the width a bit.
    End With
    If i > 1 Then
    iShp.Select
    Selection.PasteFormat
    End If
    End If
    Next
    End With
    End Sub
    [/VBA]
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •