简体   繁体   中英

VBA deletes image in body instead of header in MS-Word

I have MS Word files that have a header with 2 Text Boxes and one image (as logo) and some tables, texts and images in body.
I'm trying to remove the image in header (logo) with this VBA code:

Dim tmp As Shape
Dim dShape As Shape

For Each tmp In ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes
    If tmp.Type = msoPicture Then
        Set dShape = tmp
    End If
Next
dShape.Delete

In the first test it worked correctly! After that it removes body image instead of header image!!!

It seems we should first select the Shape we want to delete!!
I don't know why when I say shape1.Delete it thinks : let me see, mmmm... I think i is better to do shape2.Delete , so i'll do that.
any way this works:

dShape.Select
dShape.Delete

VBA is a fool (Just like its platform)!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM