Results 1 to 2 of 2

Thread: VB & WORD ( is it simple ?)

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Bath, England
    Posts
    45
    I can create a word document using VB code but how do I actually input text, tables etc.
    Any pointers or sample code would be gratefully received.
    Thanks.
    SJRigby

  2. #2
    Junior Member
    Join Date
    Oct 2000
    Posts
    18

    Simple Sample

    Add the Microsoft Word Object library to your VB project references. You can do just about anything you want in Word using VB. This should at least get you started. The easiest way to get sample code is to record a macro in Word and look at the code produced. Then, just take what you need.
    Code:
    Sub WriteToNewWordDoc
        Set wdApp = New Word.Application
        wdApp.Visible = True
        wdApp.WindowState = wdWindowStateMaximize
        wdApp.Documents.Add
        With wdApp.ActiveDocument.PageSetup
            .Orientation = wdOrientPortrait
            .TopMargin = InchesToPoints(1)
            .BottomMargin = InchesToPoints(1)
            .LeftMargin = InchesToPoints(1)
            .RightMargin = InchesToPoints(1)
            .PageWidth = InchesToPoints(8.5)
            .PageHeight = InchesToPoints(11)
        End With
        '--------------------
        'Document Title
        '--------------------
        With wdApp.Selection
            .ParagraphFormat.Alignment = wdAlignParagraphCenter
            .Font.Size = 24
            .TypeText Text:="Good spot for a document title"
            .TypeParagraph
            .TypeText Text:="Maybe a SubTitle here."
            .TypeParagraph
            .TypeParagraph
        End With
    Hope this helps!

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