referring to last posted image

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,877
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Platform
  1. Windows
I have a section of code created in a previous version of MSWORD, it is used to copy a graph from Excel to a WORD report, process is select a graph and use control C to copy to clipboard and run the following macro in MSWORD VBA, it fails under WORD 2007

Code:
Sub pictsetup()
'
' pictsetup Macro  Inserts office Graphics into report
' Macro originally recorded 19/08/99
'
    Selection.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
    Placement:=wdFloatOverText, DisplayAsIcon:=False
    Selection.ShapeRange.IncrementLeft 79.5
    Selection.ShapeRange.IncrementTop 49.5
    Selection.ShapeRange.Line.Weight = 0.25
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Visible = msoTrue
    Selection.ShapeRange.LockAspectRatio = msoTrue
    Selection.ShapeRange.WrapFormat.Type = wdWrapSquare
    Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
    Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Width = 253.45
Selection.ShapeRange.RelativeHorizontalPosition = _
        wdRelativeHorizontalPositionColumn
    Selection.ShapeRange.RelativeVerticalPosition = _
        wdRelativeVerticalPositionParagraph
    Selection.ShapeRange.Left = InchesToPoints(3.3)
    Selection.ShapeRange.Top = InchesToPoints(0.06)
    Selection.ShapeRange.LockAnchor = True
Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
End Sub

I have changed the code to the following, however how can I make sure I select the current pasted graphic and not any other graphics on the page, I am assuming an incremental count of images on the page and selecting the last one given by count is this correct

Code:
Sub pictsetup2()
'
' pictsetup Macro  Inserts office Graphics into report
' Macro originally recorded 19/08/99

    Selection.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
    Placement:=wdFloatOverText, DisplayAsIcon:=False
    intLastImage = ActiveDocument.Shapes.Count
    ActiveDocument.Shapes(intLastImage).Select
    With Selection
        .ShapeRange.IncrementLeft 79.5
        .ShapeRange.IncrementTop 49.5
        .ShapeRange.Line.Weight = 0.25
        .ShapeRange.Line.DashStyle = msoLineSolid
        .ShapeRange.Line.Visible = msoTrue
        .ShapeRange.LockAspectRatio = msoTrue
        .ShapeRange.WrapFormat.Type = wdWrapSquare
        .ShapeRange.WrapFormat.Side = wdWrapBoth
        .ShapeRange.LockAspectRatio = msoTrue
        .ShapeRange.Width = 253.45
        .ShapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
        .ShapeRange.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
        .ShapeRange.Left = InchesToPoints(3.3)
        .ShapeRange.Top = InchesToPoints(0.06)
        .ShapeRange.LockAnchor = True
        .ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
        .ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
        .ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
        .ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
    End With
    
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,932
Messages
6,122,331
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top