Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Feb 2016
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Need Word macro to select first image in .docx; set style to Normal

    Can anyone help with a Word VBA Macro to:

    Select the First Image in my DOCX & set it's "Style" to Normal ?

    Thanks.

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Styles apply to paragraphs and fonts, not to images.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. The Following User Says Thank You to macropod For This Useful Post:

    Steve8445 (2016-03-02)

  4. #3
    New Lounger
    Join Date
    Feb 2016
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    My first image in a DOCX sits alone in a para that sometimes has (inaccurately) been given the style of "Heading1" when it should have the style "Normal".

    It's always the para just before (what should be) the first "Heading1" title in the DOCX. [In the case where the "issue" exists that "title" is actually the 2nd para with Heading1 style].

    I have multiple DOCX's, some with this "issue" and some that are correct. I'd like to change the style to "Normal" so I can do further post-processing in another program. Just need the VBA to fix 1 DOCX - thanks.

  5. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    In that case, use a macro like:
    Code:
    Sub FixPic()
    ActiveDocument.InlineShapes(1).Range.Paragraphs(1).Style = wdStyleNormal
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. The Following User Says Thank You to macropod For This Useful Post:

    Steve8445 (2016-03-02)

  7. #5
    New Lounger
    Join Date
    Feb 2016
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Will this work if it's run on all my DOCX's - those that have the issue and those that don't? (I have to run it iteratively over all of them).

    I don't want to break the ones that don't have the issue.

    Thanks.

  8. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    It will work on any Word document, regardless of the file format, and will only reformat the paragraph containing the first inlineshape. It will apply the Normal Style to that paragraph regardless of what Style the paragraph already has. It will not affect any other paragraph. You might want to insert:
    On Error Resume Next
    as the first code line, in case the document you run it on has no inlineshapes.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. The Following User Says Thank You to macropod For This Useful Post:

    Steve8445 (2016-03-02)

  10. #7
    New Lounger
    Join Date
    Feb 2016
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Perfect - many thanks for your help.

Posting Permissions

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