Opening a word file(specified) using Visual Basic Command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pankajmani das
    New Member
    • Sep 2006
    • 3

    Opening a word file(specified) using Visual Basic Command

    Dear sir

    I am trying to open a word file using Visual Basic Commad. But I am failed. So, please guid me to open a perticular word or another file.

    Note: I know how to open a file using common dilog Box.
  • vbsourcer
    New Member
    • Aug 2006
    • 17

    #2
    Hey there try this ,

    1. in project menu>refference s> select .. microsoft word 9.0 object library

    Private Sub Command1_Click( )

    Dim objWord As Word.Applicatio n
    ' this would be faster with a "with objWord" but for clarity I use the explicit

    Set objWord = New Word.Applicatio n
    objWord.Visible = True
    objWord.Documen ts.Open "c:\sql performance tips.doc", , , True

    End Sub

    Comment

    • real32
      New Member
      • Sep 2006
      • 2

      #3
      Also you can try as folow:

      Set objWord = GetObject(, "Word.Applicati on") 'Look For a running copy of Word.

      If Err.Number <> 0 Then 'If Word is Not running then, run it.
      Set objWord = CreateObject("W ord.Application ")
      End If

      Err.Clear 'Clear Err object In Case Error occurred.

      With objWord
      .Caption = "My Document"
      .Documents.Add , , wdNewBlankDocum ent, True
      .ActiveDocument .PageSetup.Orie ntation = wdOrientLandsca pe
      .ActiveDocument .PageSetup.TopM argin = 72 '72 points = 1 inch.
      .ActiveDocument .PageSetup.Bott omMargin = 72
      .ActiveDocument .PageSetup.Left Margin = 36
      .ActiveDocument .PageSetup.Righ tMargin = 36
      .ActiveDocument .Content.Insert Paragraph
      .ActiveDocument .Content.Insert Paragraph
      .ActiveDocument .Content.Paste 'If you have an image in clipboard
      .ActiveDocument .Content.Insert ParagraphAfter
      .ActiveDocument .Content.Insert After " My Text Here "
      .Visible = True

      End With

      Comment

      Working...