How to add an image in the Header of a Word Document

Cannot able to fetch the selection with Header Footer view even when the cursor is available in the screen

If able to get the selection object will able to make new inline picture after selection

on run argv
    set imageName to item 1 of argv
    tell application "Microsoft Word"
        activate
        tell its active document
            set view type of view of active window to page view
            set seek view of view of active window to seek current page header
            set insertedPicture to make new inline picture at after selection of active window with properties {file name:imageName, link to file: false, save with document:true}
        end tell
    end tell
end run

Ended up with the following error:
execution error: Microsoft Word got an error: Can’t make or move that element into that container. (-10024)

First, please include ‘argv’ so it clear what is being used to create the image. imageName should probably have this form: “Drive:folder:filename.ext”

Second, unless you are working deliberately with the selection, it is usually better to work directly with the object. In this case, you want to work with the text object of the header. Conceivably, you could work with the selection here but I’m not sure of the syntax. FWIW, I would also suggest no more than a single image in the header.

set imgA to "Drive:folder:filename.ext"
tell application "Microsoft Word"
	set mad to active document
	set s1 to section 1 of active document
	make new inline picture at end of text object of (get header s1 ¬
		index header footer primary) with properties ¬
		{file name:imgA, link to file:true, save with document:true} ¬
	
end tell

NB You can reference the resulting image like so:

	inline picture 1 of text object of (get header s1 index header footer primary) of mad

Multiple images would make up a list (i.e. inline pictures of…) but I haven’t tested to know how their order is determined.