Announcement

Collapse
No announcement yet.

Need help with oWord page break code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with oWord page break code

    Hi,
    I am working with oWord com example under pbcc4 and
    am trying to import text file which is simple fixed width font.
    I need help with code to do a page break - also any ideas
    on how to specify ms word template (.dot) to us for the text
    import document. Appears the program is using default
    Normal.dot template. Can I specify a different template to
    pull the text in.
    Thanks for all you help,
    Mary

  • #2
    Mary,

    Here's a small part of a procedure that prints a rather lengthy document. It has some useful stuff in it about changing the font, page margins, etc. In terms of page breaks this works...

    vType=%wdPageBreak
    Object Call oWordSel.InsertBreak(vType)

    Here is the larger piece...

    Code:
    Sub PrintToWord(iCt As Long)
      Local strFldSp As String * 35, strFldVol As String * 10
      Dim oPageSetup As WordPageSetup
      Dim vBool As Variant, vVnt As Variant, vFileName As Variant
      Dim vText As Variant, vFileFmt As Variant
      Dim strLine As String, strFontName As String
      Dim sngFontSize As Single, sngLeftMargin As Single
      Local i As Long, iLength As Long
      Local szLocalName As Asciiz * 41, szLocation As Asciiz * 150
      Local strString1 As String, strString2 As String
      Local szText As Asciiz*400
    
      Set oWord = WordApplication In "Word.Application"
      If IsFalse IsObject(oWord) Then
         Set oWord = New WordApplication In "Word.Application"
      End If
      Let vBool = 1
      Object Let oWord.Visible = vBool
      Object Call oWord.Documents.Add To vVnt
      Set oWordDoc = vVnt
      vFileName = "C:\Tallies\Documents\Prospectus.doc"
      Object Get oWord.Selection To vVnt
      Set oWordSel = vVnt
    
      'Page Setup  ''Should Be 89 characters accross at Font = 10
      Object Get oWordDoc.PageSetup To vVnt
      Set oPageSetup = vVnt
      vVnt = 36
      Object Let oPageSetup.LeftMargin = vVnt
      Object Let oPageSetup.RightMargin = vVnt
      vVnt = 36
      Object Let oPageSetup.TopMargin = vVnt
      Object Let oPageSetup.BottomMargin = vVnt
      'Set Font Name And Size
      Object Get oWordSel.Font To vVnt
      Set oFont = vVnt
      strFontName = "Courier New"
      Let vVnt = strFontName
      Object Let oFont.Name = vVnt
      sngFontSize = 10.0
      Let vVnt = sngFontSize
      Object Let oFont.Size = vVnt
      Let vBool = 1
      Object Let oFont.Bold = vBool
      vText = "                               Commonwealth of Pennsylvania"
      Object Call oWordSel.TypeText(vText)
      Object Call oWordSel.TypeParagraph
      vText = "                     Department of Conservation and Natural Resources"
      Object Call oWordSel.TypeText(vText)
      Object Call oWordSel.TypeParagraph
      sngFontSize = 12.0
      Let vVnt = sngFontSize
      Object Let oFont.Size = vVnt
      vText = "                            Bureau of Forestry"
      Object Call oWordSel.TypeText(vText)
      Object Call oWordSel.TypeParagraph
      Object Call oWordSel.TypeParagraph
      sngFontSize = 13.5
      Let vVnt = sngFontSize
      Object Let oFont.Size = vVnt
      vText = "                            PROSPECTUS"
      Object Call oWordSel.TypeText(vText)
      Object Call oWordSel.TypeParagraph
      Object Call oWordSel.TypeParagraph
      sngFontSize = 10.0
      Let vVnt = sngFontSize
      Object Let oFont.Size = vVnt
      Let vBool = 0
      Object Let oFont.Bold = vBool
    Added later...perhaps someone else can help you with templates. I spent a number of hours fooling with them and couldn't get them to work.

    Added yet later... hadn't looked at that code in a long time! I see there were some globally defined interfaces there. Here they are...

    Global oWord As WordApplication
    Global oWordDoc As WordDocument
    Global oWordSel As WordSelection
    Global oFont As WordFont
    Last edited by Fred Harris; 14 Feb 2008, 10:40 AM.
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

    Comment


    • #3
      Fred, Thank You So Kindly for the Example Code.
      It was extremely helpful.

      Comment

      Working...
      X