1

I'm trying to add Belkin to the header of my word document.

Situation: Excel: A1 = Belkin | Word: header needs to get Belkin

Community
  • 1
  • 1
CustomX
  • 9,948
  • 30
  • 85
  • 115

1 Answers1

3

here's a quick & dirty Excel VBA to get you going - creating a new word application/word doc and pasting the content of A1 into the header ....

Sub CreateWordDocWithHeader()
Dim WApp As Word.Application
Dim WDoc As Word.Document
Dim WRng As Word.Range

    Set WApp = New Word.Application
    WApp.Visible = True
    Set WDoc = WApp.Documents.Add
    Set WRng = WDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range
    WRng = ActiveSheet.[A1]

    Set WRng = Nothing
    Set WDoc = Nothing
    Set WApp = Nothing
End Sub

Hope this helps .... Good luck miked

MikeD
  • 8,861
  • 2
  • 28
  • 50
  • thanks this works! Now I'm going to bug you once more :) What if I want to add text to an existing header? – CustomX Apr 06 '11 at 07:21
  • *How would you do it by hand?* Maybe you'd search for the correct insert position, place the insertion mark there and shoot the text ... OR you would move to a predefined bookmark .... OR prepare the header by inserting a field (maybe a custom property) and update the property's value ... make a strategy and see how you would implement it, and when you get stuck, fire a question again. Good luck – MikeD Apr 06 '11 at 10:01
  • maybe this can inspire you - it's sort of opposite of what you want, but the basic techniques are much the same .... http://stackoverflow.com/questions/3567441/extract-data-from-word-document-to-an-excel-spreadsheet/3611739#3611739 – MikeD Apr 06 '11 at 10:09
  • Hmmm, by hand I would put my cursor in the right position and paste it. But using an insertion mark sounds perfect. I presume this is a point I define and the text gets inserted here? Thank you for your help! – CustomX Apr 06 '11 at 10:51
  • yeep ... that would be a bookmark, whereby a bookmark can be a single point in a doc or an "expanded selection" including xyz letters/lines which can be overwritten by the insertion text ... define bookmarks by hand and see how they behave if you jump on them (= .select them), and then code the same in VBA – MikeD Apr 07 '11 at 11:52