Results 1 to 11 of 11

Thread: Header & Footer Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    17

    Unhappy Header & Footer Problem

    hello guys,,

    I hav a problem on inserting the data from database into the header & footer's bookmark in word document...

    let me xplain whats i'm going to do ..

    now, im doing a project where i have to use combination of Word Document + vb.net....
    i want to insert the data from database to the bookmark in the word document..i having a problem of inserting the data into the bookmark in header and footer column..the vb will ignore the bookmark because it dont detect the bookmark inside the header & footer...

    my normal codes used to be like this: ( when the bookmark not in the header & footer)

    .Selection.GoTo(what:=Word.WdGoToItem.wdGoToBookmark, Name:="Data2")

    .Selection.TypeText(Text:=Trim(Trim(dsPerson.Tables(0).Rows(0).Item(2))))

    but,,,when it involve the header and footer, i dont know how to write a code...

    plzz...anyone from out there dat can help??




  2. #2
    Member
    Join Date
    Mar 2004
    Posts
    39
    I think this is because you're in the wrong view when you access the word document, you can't get to the bookmark unless you're in Header/Footer view if the bookmark is in the Header/Footer.

    The code you get if you record a macro in Word is this:
    Code:
        ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
        Selection.TypeText Text:="vxzcv"
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    /Nisse

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    17

    Unhappy

    sory...

    i'm still dont understand how to use it...
    can u elaborate it more ?
    or can u give the example?
    where should i put the code?
    this is totally different than usual.....


  4. #4
    Member
    Join Date
    Mar 2004
    Posts
    39
    Ok, had to try it out, so I wrote a few lines. This worked for me:

    Code:
            Dim wdApp As New Word.Application
            Dim wdDoc As Word.Document
            wdDoc = wdApp.Documents.Open("C:\Test.doc")
            wdDoc.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekPrimaryHeader
            wdDoc.Bookmarks("Test").Select()
            wdApp.Selection.TypeText("Hallo world!")
            wdDoc.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekMainDocument
    /Nisse

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    17


    I'm still having a problem with dat code..

    actually, in my system , i'm using this kind of code:

    x = CreateObject("Word.Application")
    pth = Application.StartupPath

    the path is use to connect with every word doc files..
    when i tried to adjust ur code to apply it in my system, it showed an error before i can compile it...

    i dont know what to do...


  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    17

    Question



    i've tried to do dis way ,

    .Selection.GoTo(what:=.Headers(Word.WdGoToItem.wdGoToBookmark, Name:="Print"))

    but then, the compiler found that headers is not the public members on type Application.

    i tried to declare it,

    x=CreateObject("word.headersfooters")

    but dis also can't...

    when i tried to make dis way,


    .Selection.GoTo(what:=Word.WdHeaderFooterIndex.wdHeaderFooterPrimary, Name:="Print")

    the compiler gave an error dat the bookmark is not exist...
    maybe because they cannot even detect the existance of headers and footers inside the file.....

    anybody outside there can help me solve dis problem??



    anyway, thanks in advance!

  7. #7
    Member
    Join Date
    Mar 2004
    Posts
    39
    It does not exist.... in that view....

    /Nisse

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    17
    _______________________________________________
    so,,,

    in wat view it does exist???

    arghh...this thing can make my life short...
    _______________________________________________

  9. #9
    Member
    Join Date
    Mar 2004
    Posts
    39
    as I stated before:

    wdSeekCurrentPageHeader


    You mentioned you created a Application object with CreateObject. To be able to get to the diffent view and to be able to select bookmark you should create a document object in the application, then you should be able to do what I presented in earlier replies to this post.

    /Nisse

  10. #10
    Member
    Join Date
    Mar 2004
    Posts
    39
    If you had an application object named x then create a documentobject d and give it your activedocument in the application.

    Code:
    c = x.ActiveDocument
    then try something like I posted before:

    Code:
    d.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekPrimaryHeader
    d.Bookmarks("Test").Select()
    x.Selection.TypeText("Hallo world!")
    d.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekMainDocument
    /Nisse

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    17

    Thumbs up



    thank you UNisse...

    it's work!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width