none
insertfile overlapping RRS feed

  • Question

  • I added a bookmark and do insertfile (multiple times using a loop), the files are inserted (as i can search the text and found) but they all overlapping (cannot see the inserted file, only the first one shows). 

    i have tried wdlinebreak and wdSectionBreakContinuous, it will still overlap, only pagebreak works, but it leaves a blank page between insertion.

    what should i be looking into?

    With myWordApp

    .Selection.GoTo what:=-1, Name:="mybookmark"

        If i > 2 Then .Selection.InsertBreak Type:=6 ' wdlinebreak

    .Selection.InsertFile (ConSysTemplatePath & "myFile.dot")

    End With

    Wednesday, June 1, 2011 8:00 AM

Answers

  • You might get that kind of behaviour if

     a. you are executing the following line for each document you are inserting

    .Selection.Goto what:=-1, Name:="mybookmark"

     b. each document contains a bookmark "mybookmark"

    In other words, at the very least, you need to ensure that you only .goto your bookmark once, before doing all the inclusions.

     


    Peter Jamieson
    • Marked as answer by neogeo119 Wednesday, June 1, 2011 9:14 AM
    Wednesday, June 1, 2011 8:43 AM

All replies

  • Are you sure they're overlapping? Text can't overlap, only graphics (members of the Shapes collection) can overlap.

    More likely would be that each subsequent insertion is replacing the text that was inserted before. But then I'd expect only the last file to be displayed, not the first one. It would help to see all your code involved in the problem...

    FWIW I'd approach it something like this:

    Dim rng as Word.Range
    'loop on this
    Set rng = ActiveDocument.Bookmarks("mybookmark").Range
    rng.Collapse wdCollapseStart
    rng.InsertFile "filepath and name", rng


    Cindy Meister, VSTO/Word MVP
    Wednesday, June 1, 2011 8:22 AM
    Moderator
  • i suspect its overlap as i can find the text i suppose to see using Ctrl-F... but i just cannot view them, when i do a find, i found the text on a page (which i suspect overlapped) but could not see it (suppose it will be yellow highlighted)...

     

    another possibility is the whole inserted file is jammed into a table cell as the file starts with a table

    but i will try the wdcollapsestart and get back... tks alot for your help

    Wednesday, June 1, 2011 8:42 AM
  • You might get that kind of behaviour if

     a. you are executing the following line for each document you are inserting

    .Selection.Goto what:=-1, Name:="mybookmark"

     b. each document contains a bookmark "mybookmark"

    In other words, at the very least, you need to ensure that you only .goto your bookmark once, before doing all the inclusions.

     


    Peter Jamieson
    • Marked as answer by neogeo119 Wednesday, June 1, 2011 9:14 AM
    Wednesday, June 1, 2011 8:43 AM
  • Tks Peter. 

    But if I need to loop serveral times for insertfile to that bookmark position, what approach could i use instead of multiple .goto? tks.

    Wednesday, June 1, 2011 8:51 AM
  • At its simplest, put the following line after the .Goto line

    .Selection.Collapse Direction:=wdCollapseEnd

    That would mean your existing bookmark would not be overwritten or replaced.


    Peter Jamieson
    Wednesday, June 1, 2011 8:58 AM
  • oh its jammed into the first row of the table in the file inserted... as i delete the first row i could no longer find the text ...

    adding wdCollapseEnd could not solve the issue 

    Wednesday, June 1, 2011 9:08 AM
  • Got it by without .goto the markbook more than once, thanks Peter.

     

    If i = 1 Then

        .Selection.GoTo what:=-1, Name:="mybookmark"

        Set rng = .activedocument.bookmarks("mybookmark").range

        Else

        Set rng = .activedocument.GoTo(wdGoToPage, wdGoToLast)

    End If

    Wednesday, June 1, 2011 9:14 AM