CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2004
    Posts
    14

    Post Opening Word Documents

    In my program, I am wanting to open a word document and place the cursor at a predefined bookmark inside of the word document. In code, how would I open the document and go to the bookmark? Thanks a lot.

  2. #2
    Join Date
    Feb 2002
    Location
    Atlanta, Georgia, USA
    Posts
    155

    Re: Opening Word Documents

    Opening Word Documents:
    Add reference through the COM reference to Microsoft Word 9.0 COM reference library(or whatever is the latest)

    'Create a variable that represents the Application class

    Dim myWordApp As New Word.Application
    'Then assuming you already have a saved doc file in your folder Your word file.doc

    doc1=myWordApp.Documents.Open("Your word file.doc")

    Now microsoft word provides numerous objects that you can use to program any action that can be done by the word menu command.

    I do not know how to go to a bookmark by using word with .Net. However, if I am stuck, I would have done this:

    *Record a macro and see what VB code is getting registered for going to a bookmark by the menu
    *Try to simulate that code in vb.Net

  3. #3
    Join Date
    Aug 2004
    Posts
    14

    Smile Re: Opening Word Documents

    Thanks a bunch!

  4. #4
    Join Date
    Mar 2005
    Posts
    2

    Re: Opening Word Documents

    Can AnyOne Tell me how to fill a Microsoft Word textBox from VB.Net ??

    I found I can Create One Like This. But I Can't seem to fill it with text . .


    Dim oWord As New Word.Application
    Dim oDoc As Word._Document
    oWord.Visible = True
    oDoc = oWord.Documents.Open( _
    FileName:="C:\ascentia\docjobsum1.doc", _
    ConfirmConversions:=False, _
    ReadOnly:=True, _
    AddToRecentFiles:=False, _
    Format:=Word.WdOpenFormat.wdOpenFormatAuto)

    With oDoc.Shapes
    .AddTextbox (Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 100, 10)

    End With

  5. #5
    Join Date
    Mar 2005
    Posts
    2

    Re: Opening Word Documents

    the answer turned out to be

    oDoc.Shapes.Item("Text Box 1").Select()
    oWord.Selection.TypeText(Text:="Some text")

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