none
Word.Application, Insert NewPage if needed RRS feed

  • Question

  • Hello there.

    My app edits a .docx file and aims to print it. here is a sample code I use :

     Dim oWord As Word.Application
            Dim oDoc As Word.Document
           
    
            'Start Word and open the document template.
            oWord = CreateObject("Word.Application")
            oWord.Visible = False
            oDoc = oWord.Documents.Add("D:\1.docx")
            oDoc.Bookmarks.Item("Bookmark1").Range.Text = "String"  ' multi-line string
    
     Dim p As New PrintDialog
    
            p.AllowSomePages = True
            p.PrinterSettings.PrintRange = Printing.PrintRange.AllPages
            If p.ShowDialog = Windows.Forms.DialogResult.OK Then
    
    
    
                oWord.WordBasic.FilePrintSetup(Printer:=p.PrinterSettings.PrinterName, DoNotSetAsSysDefault:=1)
    
    
             
    
                oWord.PrintOut()
    
    
    
    
    
    
           
                oWord.Quit(False)
    
           
                oWord = Nothing
    
        
    

    As shown in the code , I use bookmarks to add data to the word file. my "String" that I want to add might take one entire page to be added, so how can I make sure that word inserts new page if needed ?

    Thanks


    Thursday, March 1, 2018 10:14 AM

Answers

  • Have you tested it?  I would expect Word to just automatically add pages just as it does when you are typing.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    of course I tested it before asking , it doesn't add new page to include full lines of the string

    I'm not sure what the default for the "background" parameter is in the PrintOut method, but if the default is true then maybe you are exiting the application before the remaining pages can print.

    https://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.printout.aspx?f=255&MSPPError=-2147217396

    It should be a quick and easy test to try it with the background parameter set to false.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by Kevin993 Thursday, March 1, 2018 4:05 PM
    Thursday, March 1, 2018 3:50 PM
    Moderator

All replies

  • Have you tested it?  I would expect Word to just automatically add pages just as it does when you are typing.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Thursday, March 1, 2018 1:16 PM
    Moderator
  • Have you tested it?  I would expect Word to just automatically add pages just as it does when you are typing.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    This is correct. If the amount of text you add exceeds a page a new page will be added automatically.

    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it" - MSDN User JohnWein

    Thursday, March 1, 2018 1:36 PM
  • Have you tested it?  I would expect Word to just automatically add pages just as it does when you are typing.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    of course I tested it before asking , it doesn't add new page to include full lines of the string
    Thursday, March 1, 2018 3:12 PM
  • Have you tested it?  I would expect Word to just automatically add pages just as it does when you are typing.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    This is correct. If the amount of text you add exceeds a page a new page will be added automatically.

    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it" - MSDN User JohnWein

    It is supposed to ,but i can't figure out why it doesn't work. The string I use is created in this way :

    string 1 & vb.newline & string 2 & ...

    I tested the main string, it includes multiple lines
    Thursday, March 1, 2018 3:15 PM
  • Might it be related to printing settings ? or printDialoge settings ?
    Thursday, March 1, 2018 3:16 PM
  • Have you tested it?  I would expect Word to just automatically add pages just as it does when you are typing.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    of course I tested it before asking , it doesn't add new page to include full lines of the string

    I'm not sure what the default for the "background" parameter is in the PrintOut method, but if the default is true then maybe you are exiting the application before the remaining pages can print.

    https://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.printout.aspx?f=255&MSPPError=-2147217396

    It should be a quick and easy test to try it with the background parameter set to false.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by Kevin993 Thursday, March 1, 2018 4:05 PM
    Thursday, March 1, 2018 3:50 PM
    Moderator
  • Long shot: are the fonts used in the doc installed on the system?
    Thursday, March 1, 2018 3:59 PM
  • Long shot: are the fonts used in the doc installed on the system?

    Yes, anyway I tested it with Tahoma font too. Doesn't work :|
    Thursday, March 1, 2018 4:04 PM
  • Have you tested it?  I would expect Word to just automatically add pages just as it does when you are typing.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    of course I tested it before asking , it doesn't add new page to include full lines of the string

    I'm not sure what the default for the "background" parameter is in the PrintOut method, but if the default is true then maybe you are exiting the application before the remaining pages can print.

    https://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.printout.aspx?f=255&MSPPError=-2147217396

    It should be a quick and easy test to try it with the background parameter set to false.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Setting it to false solved the issue. Thanks


    • Edited by Kevin993 Thursday, March 1, 2018 4:06 PM
    Thursday, March 1, 2018 4:05 PM