PDA

View Full Version : Moved: VBA: Picture in Word-Header? Position?



Tyreco
01-17-2017, 09:05 AM
Hi there,


i'm using a already coded excel file with macros (it was not created by me). via a button you can creat a automatic genereated word file.
now i want to change the header in the word file from a text to a picture


for this i used


Dim strLogo As String

...

strLogo = "C:Userslogo.png"

With .Sections(1)

'create header on the first page
.Headers(wdHeaderFooterFirstPage).Range.InlineShapes.AddPicture Filename:=strLogo, _
LinkToFile:=False, SaveWithDocument:=True


the picture shows up in the word file but i can't find any possibility to define it's position
would be nice to fix it with an absoulte position.


could anyone please help?

macropod
01-17-2017, 02:28 PM
I used


Dim strLogo As String

...

strLogo = "C:Userslogo.png"

With .Sections(1)

'create header on the first page
.Headers(wdHeaderFooterFirstPage).Range.InlineShapes.AddPicture Filename:=strLogo, _
LinkToFile:=False, SaveWithDocument:=True


the picture shows up in the word file but i can't find any possibility to define it's position
would be nice to fix it with an absoulte position.
You're inserting the picture as an inlineshape, which means it's positioning is determined by the format of the paragraph it's inserted into. Changing the paragraph format may be all you need to do; otherwise, insert the object as a shape - or change the inlineshape to a shape via .ConvertToShape - and position the shape object accordingly.

Tyreco
01-18-2017, 08:42 AM
Thanks for your answer! There are two pictures in the document
If i just use ActiveDocument.InlineShapes(1).ConvertToShape the picture(s) doesn't appear anymore?!

Could you please help me with some codes?

gmaxey
01-19-2017, 07:57 AM
Can you attach your document with some detail on which shape you want positioned where?

Tyreco
01-19-2017, 09:00 AM
Can you attach your document with some detail on which shape you want positioned where?


The old code for header and footer is:


With wdoc


.PageSetup.DifferentFirstPageHeaderFooter = False




With .Sections(1)

'header on first page
.Headers(wdHeaderFooterFirstPage).Range.Text = vbCrLf & "sometext"
.Headers(wdHeaderFooterFirstPage).Range.Font.Bold = True
.Headers(wdHeaderFooterFirstPage).Range.Font.Size = 12

'footer on first page
.Footers(wdHeaderFooterFirstPage).Range.Text = vbCrLf & vbCrLf & CStr(Range("A95")) & vbCrLf & CStr(Range("A96")) & vbCrLf & CStr(Range("A97")) _
& vbCrLf & CStr(Range("A98")) & vbCrLf & CStr(Range("A99")) & vbCrLf & CStr(Range("A100")) & vbCrLf & CStr(Range("A101"))

.Footers(wdHeaderFooterFirstPage).Range.Font.Bold = False
.Footers(wdHeaderFooterFirstPage).Range.Font.Size = 7

End With


.PageSetup.DifferentFirstPageHeaderFooter = True
.PageSetup.OddAndEvenPagesHeaderFooter = False




End With






Now i want to exchange the header with a picture and also add a picture to the footer (the text from the excel tables should stay)

So i wrote:


With wdoc


.PageSetup.DifferentFirstPageHeaderFooter = False
strLogo = "C:\...\logo.png"


With .Sections(1)

'header to first page
.Headers(wdHeaderFooterFirstPage).Range.InlineShapes.AddPicture Filename:=strLogo, _
LinkToFile:=False, SaveWithDocument:=True


I didn't changed the footer so far...