Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Jan 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Word 2013 picture paste, resize, and move macro.

    Howdy,

    I've been trying to get a macro to past a picture I have located in the clipboard to my word documents, position it to 'behind text', unlock the aspect ratio, set the height = 7" and the width =10", and finally move the picture 4 clicks left and 1 click down (click as in pressing the keyboard arrow key 4 times and the down key 1 time in correspondence with the grid lines).

    After searching this form I came up with this macro I've been trying to get work... but I am no good at programming right now, need to get some books...

    Any help would be appreciated. Thanks.

    Code:
    Sub Demo()
    Selection.Paste
    Application.ScreenUpdating = False
    Selection.ShapeRange.LockAspectRatio = msoFalse
    Selection.ShapeRange.Height = 7
    Selection.ShapeRange.Width = 10
    Selection.ShapeRange.WrapFormat.Type = wdWrapBehind
    Selection.MoveLeft Unit:=wdCharacter, Count:=4
    Selection.MoveDown Unit:=wdCharacter, Count:=4
    Application.ScreenUpdating = True
    End Sub

  2. #2
    New Lounger
    Join Date
    Jan 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Can't get it to move the picture over 4 and down 1 now.. Any ideas?

    Sub Demo()

    Selection.PasteSpecial Placement:=wdWrapBehind, DisplayAsIcon:=False

    'Application.ScreenUpdating = False

    Dim myShape As Shape
    Set myShape = Selection.ShapeRange(1) '<--------- Went to another word document and now the macro keeps ending here. Runtime error 5. Invalid procedure call or argument

    'myShape.IncrementLeft (-4)
    'myShape.IncrementTop (1)
    myShape.LockAspectRatio = msoFalse
    myShape.Height = 140
    myShape.Width = 50
    myShape.WrapFormat.Type = wdWrapBehind

    'Application.ScreenUpdating = True

    End Sub
    Last edited by Nexor; 2013-01-30 at 15:05.

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    I think the problem is likely to be the positioning of the graphic. If the graphic is set to Inline then it is an InlineShape and therefore not a member of the ShapeRange shapes. Your graphic needs to be floating to be considered as a member of ShapeRange.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    New Lounger
    Join Date
    Jan 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the reply Andrew. I tried setting as Inline Shape but still no luck, VBA says 'requested member does not exist'

    Any other ideas? I'm at a loss for how to get this working... still googling but nothing yet.

  5. #5
    New Lounger
    Join Date
    Jan 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Then tried this (found this on google) but it just Exits sub right after the first IF.

    Code:
    Sub Demo()
    
    Selection.PasteSpecial Placement:=wdWrapBehind, DisplayAsIcon:=False
    
    '---------------------Sub ResizePics()
        Dim shp As Word.Shape
        Dim ishp As Word.InlineShape
        
        If Word.Selection.Type <> wdSelectionInlineShape And _
            Word.Selection.Type <> wdSelectionShape Then
            Exit Sub
        End If
        
        If Word.Selection.Type = wdSelectionInlineShape Then
            Set ishp = Word.Selection.Range.InlineShapes(1)
            'ishp.WrapFormat.Type = wdWrapBehind
            ishp.LockAspectRatio = False
            ishp.Height = InchesToPoints(1.78)
            ishp.Width = InchesToPoints(3.17) '<--- I haven't modified these for my purposes yet
        Else
            If Word.Selection.Type = wdSelectionShape Then
                Set shp = Word.Selection.ShapeRange(1)
                shp.WrapFormat.Type = wdWrapBehind
                shp.LockAspectRatio = False
                shp.Height = InchesToPoints(1.78)
                shp.Width = InchesToPoints(3.17)
            End If
        End If
    End Sub
    That is going to be a problem, I did not think of that ... the shape may or may not selected. Word is pasting it in from the clipboard so I have no way of knowing if it is selected that way by default.


    Cant even get this stuff to work.


    Any help is so gratefully appreciated.

  6. #6
    New Lounger
    Join Date
    Jan 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Tried ElseIf on one line and 2nd program does not run still. If I comment out the

    Code:
    If Word.Selection.Type <> wdSelectionInlineShape And _
            Word.Selection.Type <> wdSelectionShape Then
            Exit Sub
        End If
    it only pasts the picture from clipboard than steps to

    If Word.Selection.Type = wdSelectionInlineShape Then

    ElseIf Word.Selection.Type = wdSelectionShape Then

    End If

  7. #7
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Perhaps you need to explain fully what the macro's purpose actually is.

    You start by pasting something into a document but we (and the macro) have no idea of what might be in the clipboard at this point. The paste includes a command to WrapBehind so perhaps it fails if the clipboard doesn't contain a floating image as its only content. Then you start using the selection object but it is unlikely anything is selected at this point - I would expect the cursor to be sitting as an insertion point immediately after the pasted content at this point.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  8. #8
    New Lounger
    Join Date
    Jan 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Andrew, good call.

    I am taking a screen shot of a graph via the print screen button. After that I past the screen shot into Word via ctrl-v. Then unlock aspect ratio and I re-size the image to 7" high x 10" wide (this is being pasted onto a Landscape oriented document). The next step is to 'set behind text' so that I can move and position the image where I want it on the page which is exactly 4 presses of the left arrow key and 1 press of the down area key.

    Then I save the document, delete the current graph image in the document and start all over again.

    Hope that explained things better.

    Thanks.

  9. #9
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    I assume that when you run the macro there are no graphics in the document so we can dispense with the selection object and do it this way which removes a lot of the unknowns
    Code:
    Sub Demo()
      Application.ScreenUpdating = False
      Selection.Paste
      If ActiveDocument.InlineShapes.Count = 1 Then
        ActiveDocument.InlineShapes(1).ConvertToShape
      End If
      If ActiveDocument.Shapes.Count = 1 Then
        With ActiveDocument.Shapes(1)
          .LockAspectRatio = msoFalse
          .Height = InchesToPoints(7)
          .Width = InchesToPoints(10)
          .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
          .RelativeVerticalPosition = wdRelativeVerticalPositionPage
          .Top = InchesToPoints(1) ' change value as needed
          .Left = InchesToPoints(2) ' change value as needed
        End With
      End If
      Application.ScreenUpdating = True
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  10. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    Nexor (2013-02-01)

  11. #10
    New Lounger
    Join Date
    Jan 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Andrew...
    Modified the following

    Works beautifully. Thank you!

    Code:
    Sub Demo()
      If ActiveDocument.Shapes.Count = 3 Then
        ActiveDocument.Shapes(3).Select
        Selection.ShapeRange.Delete
      End If
      Application.ScreenUpdating = False
      Selection.Paste
      If ActiveDocument.InlineShapes.Count = 1 Then
        ActiveDocument.InlineShapes(1).ConvertToShape
      End If
      If ActiveDocument.Shapes.Count = 3 Then
        With ActiveDocument.Shapes(3)
          .WrapFormat.Type = wdWrapBehind
          .LockAspectRatio = msoFalse
          .Height = InchesToPoints(7)
          .Width = InchesToPoints(10)
          .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
          .RelativeVerticalPosition = wdRelativeVerticalPositionPage
          .Top = InchesToPoints(1.1) ' change value as needed
          .Left = InchesToPoints(0.5) ' change value as needed
        End With
      End If
      Application.ScreenUpdating = True
    End Sub

Posting Permissions

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