CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2001
    Location
    Israel
    Posts
    94

    How can I execute Word

    I have to open a word document during runtime from VB, I managed doing it when the word is already up, but how do I execute it if it is not activated?

    FatMan


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: How can I execute Word

    You can use the CreateObject fucntion to create an instance of word

    set appWord = CreateObject("Word.Application")




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: How can I execute Word

    Here is a good example

    'ref to word8 lib
    'Create an empty class to reference the Word Object
    Dim w1 As Word.Application

    Private Sub cmdAddDocument_Click()

    'Create a new document
    w1.Documents.Add

    End Sub

    Private Sub cmdAddText_Click()

    'Test to see if there is a document open
    If w1.Documents.Count < 1 Then
    MsgBox "No documents open"
    Exit Sub
    End If

    'Set the font size
    w1.Selection.Font.Size = txtSize.Text

    'Set the font weight etc.
    w1.Selection.Font.Bold = IIf(chkBold.Value = 1, True, False)
    w1.Selection.Font.Italic = IIf(chkItalic.Value = 1, True, False)
    w1.Selection.Font.Underline = IIf(chkUnderline.Value = 1, True, False)

    'Set the alignment
    w1.Selection.ParagraphFormat.Alignment = drpJustification.ListIndex' (combo)

    'Type the text
    w1.Selection.TypeText txtTypeText.Text

    End Sub

    Private Sub cmdPrint_Click()

    'Print out
    w1.ActiveDocument.PrintOut

    End Sub

    Private Sub Form_Load()

    'Create a new instance of word
    Set w1 = New Word.Application

    'Initialize Word as visible
    Option1_Click 0

    'Make the default value the first in the list
    drpJustification.Text = drpJustification.List(0)

    End Sub

    Private Sub Form_Terminate()

    'Close the Word application (not saving changes)
    w1.Quit False
    Set w1 = Nothing

    End Sub

    Private Sub Option1_Click(Index As Integer)

    'Make word invisible / visible
    w1.Visible = IIf(Index = 0, True, False)

    End Sub


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured