none
Macro to alert if graphic in the word file RRS feed

  • Question

  • Hello All,

    Is there any macro to give an alert if there is a graphic in the active word document.

    Regards

    John

    Wednesday, November 6, 2019 3:34 AM

Answers

  • @John,

    If you mean "graphic" as "Pictures", VBA code would be like this.
    Sub Alert_Image()
        Dim cnt As Integer: cnt = 0
        Dim shp As Shape
        For Each shp In ThisDocument.Shapes
            If (shp.Type = 13) Then
                cnt = cnt + 1
            End If
        Next
        ' ---
        If (cnt > 0) Then
            MsgBox "There are " & cnt & " Pictures in this document!!"
        End If
    End Sub
    Regards,

    Ashidacchi -- http://hokusosha.com

    • Marked as answer by Johnmiller1234 Thursday, November 7, 2019 4:25 PM
    Wednesday, November 6, 2019 7:41 AM

All replies

  • Hi John,

    What do you mean by "graphic"?
    Does "graphic" means "Pictures", "Shapes"?

    I'd like you to define "graphic". 
    Regards,

    Ashidacchi -- http://hokusosha.com

    Wednesday, November 6, 2019 7:30 AM
  • @John,

    If you mean "graphic" as "Pictures", VBA code would be like this.
    Sub Alert_Image()
        Dim cnt As Integer: cnt = 0
        Dim shp As Shape
        For Each shp In ThisDocument.Shapes
            If (shp.Type = 13) Then
                cnt = cnt + 1
            End If
        Next
        ' ---
        If (cnt > 0) Then
            MsgBox "There are " & cnt & " Pictures in this document!!"
        End If
    End Sub
    Regards,

    Ashidacchi -- http://hokusosha.com

    • Marked as answer by Johnmiller1234 Thursday, November 7, 2019 4:25 PM
    Wednesday, November 6, 2019 7:41 AM
  • Hello Ashidacchi,

    Thank you, the macro works goods, however it gives message one graphic in the word file whereas the word file has 2 graphics.

    Attached the word file in the below link.

    https://gofile.io/?c=txz09b

    John

    Wednesday, November 6, 2019 8:47 AM
  • Hi John,

    In the file you shared, a linked image is involved that I cannot open in my environment.


    I hope you will share the Linked Image.

    Regards,

    Ashidacchi -- http://hokusosha.com

    Wednesday, November 6, 2019 9:30 AM