jimrward
Well-known Member
- Joined
- Feb 24, 2003
- Messages
- 1,897
- Office Version
- 2021
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
- 2003 or older
- Platform
- 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
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 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