Results 1 to 3 of 3

Thread: exporting to word?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    9
    I have a database that holds personal information such as First Name, Last Name, Address, Postal Code, etc...and I was wondering if there was a way to export this information into a word document. Say in my visual basic program the user is viewing a record, and then wants to write them a letter...how can i export this information into word, as mentioned before.....any tips, ideas, or how-tos would be greatly appreciated.

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

    Export 2 Word

    U'll need 2 declare a word object and get the field values either from the form or the database(using a query) and use the code below to save it in doc (or rtf, or html or ascii text ) format.

    Dim w As New Word.Application ' instance of MsWord

    Dim strData as String

    ...' Query to retrieve values from the Database
    ...' or expressions to retrieve values from forms
    ...' Store these values in strData


    w.Documents.Add ' Add a new document to word session
    w.Selection.TypeText (strMsg)
    w.ChangeFileOpenDirectory (App.Path)

    w.ActiveDocument.SaveAs FileName:="test" & ".doc", _
    FileFormat:=wdFormatDocument, LockComments:=False, _ Password:="", _
    AddToRecentFiles:=True, WritePassword:="", _
    ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False

    w.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    w.Application.Quit
    Set w = Nothing
    ...
    ...
    ..

    This will save the value in strData in a word file (.doc) in the directory App.path with filename Test.doc

    If U want a sample prg, let me know and I'll mail it to you.

    The SaveAs portion of this code is got by going to MsWord and clicking Tools->Macro->Record New Macro and give macro name.
    Then type any text in the doc. U then click file,->Save As
    and then give a filename an hit Ok.

    Then Tools->Macro->Stop Recording.

    And finally Tools->Macro->Macros and Click Edit after selecting the macro u saved.

    Just cut and paste the code generated.

    To save it as another type(html, rtf, etc) select that type in when saving the doc.

    If u want more info on manipulating word , let me know....

    Hemang

  3. #3
    Member
    Join Date
    Jul 2005
    Posts
    42

    Re: exporting to word?

    hi zambian,

    my situation is that i use vb6 and active report as my report function. the only thing trouble me is that whenever i export to *.rtf and then the box gone also microsoft word cannot identify as header and footer it.

    can u help me?
    thank you.

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