none
Range.Copy annoyances RRS feed

  • Question

  • My situation is, that I want copy a Word-document page by page into separate table cells (Range.Copy followed by PasteSpecial as EnhancedMetafile) in another word document. This is to keep any existing formatting.

    For a given page to be copied, Range.Start is set by Document.GoTo(wdGotoPage, wdGotoAbsolute, pageNumber, Type.Missing).
    Range.End is set either to the start of the next page OR to the end of the document (Document.Range(Type.Missing, Type.Missing).End) if we are on the last page. Range.Text now actually contains the contents of that page.

    Now I do a Range.Copy() (to copy the contents to the clipboard) but in a specific situation Range.Text is now changed so it contains the complete chapter i.e. some contents from the previous page (the chapter starts on the previous page and ends on the current page). I assume this is because Range.End implicitely makes a Select on the Range and includes the Control Character(s) for Chapter End...!? I tried that in MS-Word and by highlighting the control character the whole chapter is selected.

    Now my thought is, that I could filter out the 'chapter end '-control codes (and move the Range.End accordingly) to only select the contents on the page - but where to find a list of MS Word control codes?

    Does anyone have a better idea?




    Thursday, December 12, 2013 2:44 PM

Answers

  • The '¤'symbol is a table's end-of-cell or end-of-row marker; it has nothing to do with chapters or pages. When you're working with tables and copying cell contents, you need to recognize that 'page' definitions don't have quite the same meaning that they do in other contexts. In this case, you might do better to work though the rectangles on the page. For example, you might use something based on:
    ActiveDocument.ActiveWindow.Panes(1).Pages(2).Rectangles(1).Range.Copy
    where '2' is the page #.

    As for your 'PasteSpecial as EnhancedMetafile' to preserve formatting, that's a fairly brute-force method unless all you're after is a picture of the page. If you want editable text, try something based on:
    .PasteAndFormat (wdFormatOriginalFormatting)


    Cheers
    Paul Edstein
    [MS MVP - Word]



    • Edited by macropodMVP Friday, December 13, 2013 7:00 AM
    • Marked as answer by Tricky_T Friday, December 13, 2013 8:50 AM
    Friday, December 13, 2013 6:41 AM

All replies

  • I don't know what you mean by a "chapter end" control code. Word has no such thing. What, more specifically, do you mean?

    (Note: I'm moving this discussion to the Word for Developers forum as the issue has nothing to do with the VSTO technology and everything to do with Word. You'll find more people there who can help...)


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, December 12, 2013 5:17 PM
    Moderator
  • By "chapter end" I mean the ascii sequences behind the '¤'-sign in MS Word - the character identifying the end of a chapter (by chapter I mean the text related to a specific heading (including the heading itself))..

    This is in fact a quite VSTO-specific question related to MS Word: How to copy/paste a single page (using VSTO) - and only that page.

    Thursday, December 12, 2013 9:39 PM
  • The '¤'symbol is a table's end-of-cell or end-of-row marker; it has nothing to do with chapters or pages. When you're working with tables and copying cell contents, you need to recognize that 'page' definitions don't have quite the same meaning that they do in other contexts. In this case, you might do better to work though the rectangles on the page. For example, you might use something based on:
    ActiveDocument.ActiveWindow.Panes(1).Pages(2).Rectangles(1).Range.Copy
    where '2' is the page #.

    As for your 'PasteSpecial as EnhancedMetafile' to preserve formatting, that's a fairly brute-force method unless all you're after is a picture of the page. If you want editable text, try something based on:
    .PasteAndFormat (wdFormatOriginalFormatting)


    Cheers
    Paul Edstein
    [MS MVP - Word]



    • Edited by macropodMVP Friday, December 13, 2013 7:00 AM
    • Marked as answer by Tricky_T Friday, December 13, 2013 8:50 AM
    Friday, December 13, 2013 6:41 AM
  • Thanks a lot Paul.

    I didn't recognize the tables but you are right - that is the case and that makes very good sense. I will try and copy the page as you describe instead.

    I copy/paste the document as an image to keep the formatting but also because the user is not allowed to edit the contents (it is quality related documentation that should not be changed).

    Thanks for your attention and thanks for the answer. It really helped me out!

    Friday, December 13, 2013 8:57 AM