Results 1 to 4 of 4

Thread: HELP: Saving to MS Word

  1. #1
    Guest

    Question

    I am doing a project that requires that info returned by a search (eg. SQL) be shown on a form and also have an option be to save to MS Word.
    I am not clear how to save the information to MSWord as i am only a beginner. Please help!!
    Very much appreciated.

    :}
    msfeline

  2. #2
    Guest

    Cool

    Hmm.. ahhh.. ok.. first off all you have to set the references
    of your msword application. If your using msword 97 you
    have to select the references word 8.0 to use this example.

    Make a commandbutton on your form and place this code under it.

    Code:
    Private Sub Command1_Click()
        
        Dim objWordApp As Object
        
        Set objWordApp = GetObject("", "Word.Application.8")
        If objWordApp Is Nothing Then
            Set objWordApp = CreateObject("Word.Application.8")
        End If
        
        objWordApp.Documents.Open FileName:="C:\MyWord.Doc"
        
        objWordApp.Documents(1).SaveAs "c:\finish.Doc"
        objWordApp.Documents(1).Close
        objWordApp.Quit
        
        Dim RetVal
        RetVal = Shell("C:\Program Files\Microsoft Office\Office\Winword.exe C:\Myword1.Doc", 1)
        
    End Sub
    This example shows you a way to open a document and save
    it under a diferent name. This example will place all the document on you root hd. Goodluck my friend..

  3. #3
    Guest

    Talking

    Hey, thanks a lot.
    It works!
    :}

    I need further help ....

    Scenario 1
    ==========
    Let's say that i have to display the search results in a datareporter for printing. The print icon will be there for the user to print this report. I wonder how do i capture the contents of the report, headers etc. into Word?

    Scenario 2
    ==========
    If the search results are displayed in a listview, listbox, or label etc. How do i capture these individual item's value and dump them into Word with some basic formatting (eg.breaks or spaces between different values).


    Would greatly appreciate if you could help me again!


  4. #4
    Guest

    Talking

    Its, i think very dificult to capture the headers of your
    datareport. Maybe you cant do that, i dont know.
    But what you can do is when your finish your command
    with a SQL statement. You can read the value's that was
    generated by your dataenvironment. So when everything is ready.
    You can place all those value's in word.


    TiP:

    You can use almost everything that was generated by visual
    basic for applications in word. In your visual basic project.


    Example:

    Code:
    objWordApp.Selection.TypeText Text:="Hello my friend!"
    This line of code will place some text in your document.


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