Macro works, but only if you 'step' through it - Word 2000

Discussion in 'Word' started by PhillipN, Dec 5, 2016.

  1. PhillipN

    PhillipN

    Joined:
    Dec 5, 2016
    Messages:
    2
    Likes Received:
    0
    Can anyone tell me what is wrong with this code?
    It loads a specific picture file, resizes it and sets it 'behind' text at the cursor point, just as it is meant to do but only if run under DEBUG, stepping through each line. If you just RUN it, it does nothing, but does not give an error.
    I guess it has something to do with initialization or completion, but can't figure out what.

    Sub pcn()
    '
    ' pcn Macro
    ' Macro to insert signature 2016/11/20
    '

    Dim oDialog As Dialog
    Dim oImage As Object
    Dim oRng As Range
    Set oImage = Selection.InlineShapes.AddPicture("D:\DOCUMENTS\PCN\pcnsig.png")
    With oImage
    .LockAspectRatio = msoTrue
    .Height = 0.2 * .Height
    .Width = 0.2 * .Width
    Set oRng = oImage.Range
    .ConvertToShape
    End With
    With oRng.ShapeRange(1)
    .ZOrder msoSendBehindText
    .WrapFormat.Type = wdWrapNone
    End With
    Set oDialog = Nothing
    Set oImage = Nothing
    Set oRng = Nothing

    End Sub


    The code from derived from examples culled from contributions elsewhere on this site. Thanks!
    I am trying to run it on an ancient version of Word - 2000 under windows 10. It still works ok and I don't have problems with other versions of this macro.

    PhillipN
     
    PhillipN, Dec 5, 2016
    #1
    1. Advertisements

  2. PhillipN

    macropod

    Joined:
    Mar 2, 2012
    Messages:
    177
    Likes Received:
    10
    There doesn't appear to be anything inherently 'wrong' with your code, though it could be made more efficient. Try:

    Code:
    Sub pcn()
    Dim iShp As InlineShape, Shp As Shape
    Set iShp = Selection.InlineShapes.AddPicture("D:\DOCUMENTS\PCN\pcnsig.png")
    With iShp
      .LockAspectRatio = msoTrue
      .Height = 0.2 * .Height
      Set Shp = .ConvertToShape
    End With
    With Shp
      .ZOrder msoSendBehindText
      .WrapFormat.Type = wdWrapNone
    End With
    Set iShp = Nothing: Set Shp = Nothing
    End Sub
     
    macropod, Dec 6, 2016
    #2
    PhillipN likes this.
    1. Advertisements

  3. PhillipN

    PhillipN

    Joined:
    Dec 5, 2016
    Messages:
    2
    Likes Received:
    0
    Ahhh! Thank you! That was quick!

    And it works just dandy.
    The only tweak is that on my old steam-driven version, it does need a ".Width = 0.2 * .Width" line as well, otherwise the "LockAspectRatio" isn't enough.

    For anyone who wants to use this: the "0.2" factor in the Height / Width lines can be edited to suit the size of the png file image. Alternatively you could make the png image the right size and omit those two lines, but that would be less flexible.

    Thanks again, macropod, for taking out the garbage. It looks and works MUCH better
    P
     
    PhillipN, Dec 6, 2016
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jsduiahd
    Replies:
    0
    Views:
    575
    jsduiahd
    Jul 2, 2011
  2. Adrena1in
    Replies:
    0
    Views:
    2,522
    Adrena1in
    Dec 6, 2013
  3. Rajan Kandola
    Replies:
    0
    Views:
    959
    Rajan Kandola
    May 6, 2014
  4. oao
    Replies:
    0
    Views:
    308
  5. Gen Book

    WORD 2010 vs 2000

    Gen Book, Jan 15, 2016, in forum: Word
    Replies:
    0
    Views:
    225
    Gen Book
    Jan 15, 2016
  6. software_ss
    Replies:
    0
    Views:
    187
    software_ss
    Apr 18, 2016
  7. Yomero
    Replies:
    5
    Views:
    310
    macropod
    Aug 30, 2016
  8. Lup
    Replies:
    6
    Views:
    159
Loading...