none
Moving a picture in a macro RRS feed

  • Question

  • I am an A level student and wants to know how to move a picture while the macro is been recorded because you cannot click and drag the picture or select the wrap option in order to move the picture in the top corner. Any help regarding this would be appreciated ICT exam is next week reply asp! plz
    Wednesday, March 9, 2016 5:43 PM

Answers

  • Hi, Saud Mushtaq

    I agree with macropod. you cant move picture while recording the macro. if you want to do it with code then I have mentioned a code below you can try.

    Sub Demo()
    Application.ScreenUpdating = False
    Dim Rng As Range, Shp As Shape
    With Application.Dialogs(wdDialogInsertPicture)
      .Display
      If .Name <> "" Then
        Set Rng = Selection.Range
        Rng.Collapse
        Set Shp = ActiveDocument.InlineShapes.AddPicture(FileName:=.Name, _
          SaveWithDocument:=True, Range:=Rng).ConvertToShape
        With Shp
          .LockAspectRatio = True
          .Left = CentimetersToPoints(1.5)
          .Top = CentimetersToPoints(0.5)
          .Width = CentimetersToPoints(2.5)
          .WrapFormat.Type = wdWrapBehind
        End With
      GoTo Done
      End If
    End With
    Done:
    Set Rng = Nothing: Set Shp = Nothing
    Application.ScreenUpdating = True
    End Sub

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Thursday, March 10, 2016 4:28 AM
    Moderator

All replies

  • You can't do that with the macro recorder. You have to write the code to move the picture - and the code for that depends on whether it's formatted in-line with text or something else.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, March 10, 2016 1:21 AM
  • Hi, Saud Mushtaq

    I agree with macropod. you cant move picture while recording the macro. if you want to do it with code then I have mentioned a code below you can try.

    Sub Demo()
    Application.ScreenUpdating = False
    Dim Rng As Range, Shp As Shape
    With Application.Dialogs(wdDialogInsertPicture)
      .Display
      If .Name <> "" Then
        Set Rng = Selection.Range
        Rng.Collapse
        Set Shp = ActiveDocument.InlineShapes.AddPicture(FileName:=.Name, _
          SaveWithDocument:=True, Range:=Rng).ConvertToShape
        With Shp
          .LockAspectRatio = True
          .Left = CentimetersToPoints(1.5)
          .Top = CentimetersToPoints(0.5)
          .Width = CentimetersToPoints(2.5)
          .WrapFormat.Type = wdWrapBehind
        End With
      GoTo Done
      End If
    End With
    Done:
    Set Rng = Nothing: Set Shp = Nothing
    Application.ScreenUpdating = True
    End Sub

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Thursday, March 10, 2016 4:28 AM
    Moderator
  • Thank you, i think i need to learn the coding first then.
    Sunday, March 13, 2016 2:24 PM
  • thank you, will try that code. 
    Sunday, March 13, 2016 2:25 PM
  • Hi, Saud Mushtaq

    if any of the answers are helpful to solve your issues then click "Marked As Answered".

    Regards

    Deepak 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, March 14, 2016 6:29 AM
    Moderator