Results 1 to 5 of 5

Thread: Doc File saving

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Location
    Pakistan
    Posts
    24

    Arrow Doc File saving

    i am generating reports as DOC files. I have a problem that i want to save a document as doc file in a folder in the program directory where there is application that is it should use app.path and then the folder name. In the sample below i have to specify the folder location while i want to use app.path. Any help regarding this

    Dim wordapp As Word.Application
    Dim thisdoc As Document
    Dim thisrange As Range
    Set wordapp = CreateObject("word.application")
    If wordapp Is Nothing Then
    MsgBox "could notstart word"
    End If
    wordapp.Documents.Open App.Path & "\templates\SM-00.dot"
    Set thisdoc = wordapp.ActiveDocument
    thisdoc.FormFields(1).Result = txtName.Text
    thisdoc.FormFields(2).Result = txtNo.Text
    thisdoc.FormFields(3).Result = txtRef.Text
    thisdoc.FormFields(4).Result = mskDate.Text
    thisdoc.FormFields(5).Result = txtSpec.Text
    thisdoc.FormFields(6).Result = txtZN.Text
    thisdoc.FormFields(7).Result = txtGm.Text
    thisdoc.FormFields(8).Result = txtKOH.Text


    thisdoc.SaveAs "d:\Reports\SM-" & txtNo.Text & ".doc"
    MsgBox " Doc is saved"
    wordapp.Quit
    Set wordapp = Nothing
    Set thisdoc = Nothing


    "d:\Reports, this should be as App.path & \Reports....
    Last edited by ieesab; Dec 18th, 2005 at 10:22 AM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Doc File saving

    Here you go:
    VB Code:
    1. thisdoc.SaveAs app.path & "\Reports\SM-" & txtNo.Text & ".doc"

  3. #3
    Lively Member fifo's Avatar
    Join Date
    Dec 2005
    Location
    HaiPhong, Vietnam
    Posts
    77

    Re: Doc File saving

    But I want to add some object such as table, line in this doc. How can I do now? Please show me.
    !Have fun!

  4. #4
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Doc File saving

    If you want to add a table you can use the following code:
    VB Code:
    1. 'This example sets myRange equal to the contents of the active document, collapses myRange, and then inserts a 2x2 table at the end of the document.
    2.  
    3. Set myRange = ThisDoc.Content
    4. myRange.Collapse Direction:=wdCollapseEnd
    5. ThisDoc.Tables.Add Range:=myRange, NumRows:=2, NumColumns:=2
    6.  
    7. 'This example creates a 5x5 table in the active document and then applies a predefined format to it.
    8.  
    9. Selection.Collapse Direction:=wdCollapseStart
    10. Set myTable = ThisDoc.Tables.Add(Range:=Selection.Range, _
    11. NumRows:=5, NumColumns:=5)
    12. myTable.AutoFormat Format:=wdTableFormatClassic2
    13.        
    14. 'This example inserts numbers and text into the first column of the first table in the active document.
    15.  
    16. num = 90
    17. For Each acell In ThisDoc.Tables(1).Columns(1).Cells
    18.     acell.Range.Text = num & " Sales"
    19.     num = num + 1
    20. Next acell
    CS

  5. #5
    Lively Member fifo's Avatar
    Join Date
    Dec 2005
    Location
    HaiPhong, Vietnam
    Posts
    77

    Re: Doc File saving

    very cool! thanks
    !Have fun!

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