I have the following code:
Sub CreateRapport()
Dim wdApp As Object
Dim wd As Object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wd = wdApp.Documents.Add
wdApp.Visible = True
Sheets("Rapport").Activate
Set Rng = ThisWorkbook.ActiveSheet.Range("A1:E76")
Rng.Copy
With wd.Range
.Collapse Direction:=0 'Slutet av dokumentet
.InsertParagraphAfter 'Lägg till rad
.Collapse Direction:=0 'Slutet av dokumentet
.PasteSpecial False, False, True 'Pasta som Enhanced Metafile
End With
End Sub
What it does is that it creates a word document with the data from range A1:E76
I want to insert a header in this word document that contains a picture and a name. The name in this header is in cell A1 in the same sheet.
Would be very thankful if anyone could help me with this. Thank you.
How to add text from cell A1 to the document:
How to turn the current text into a header:
How to add an image:
If you put the above code together and add it directly after the line
wdApp.Visible = True
you will get a header with an image at the end, but I can't tell from your question exactly how you want the document to look.EDIT
Code to show current header:
Show normal view:
Putting it all together, paste this after the line
wdApp.Visible = True
, this time without setting the style:EDIT 2
My suggestion about transferring the embedded image from Excel to Word is to use copy and paste:
The code needs to go somewhere near the
wdApp.Selection.TypeText
command, depending on where you want the image to display.EDIT 3
Code for adding page number field: