|
-
Dec 18th, 2005, 10:18 AM
#1
Thread Starter
Junior Member
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.
-
Dec 18th, 2005, 10:53 AM
#2
Re: Doc File saving
Here you go:
VB Code:
thisdoc.SaveAs app.path & "\Reports\SM-" & txtNo.Text & ".doc"
-
Jan 9th, 2006, 06:34 AM
#3
Lively Member
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!

-
Jan 9th, 2006, 07:22 AM
#4
Re: Doc File saving
If you want to add a table you can use the following code:
VB Code:
'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.
Set myRange = ThisDoc.Content
myRange.Collapse Direction:=wdCollapseEnd
ThisDoc.Tables.Add Range:=myRange, NumRows:=2, NumColumns:=2
'This example creates a 5x5 table in the active document and then applies a predefined format to it.
Selection.Collapse Direction:=wdCollapseStart
Set myTable = ThisDoc.Tables.Add(Range:=Selection.Range, _
NumRows:=5, NumColumns:=5)
myTable.AutoFormat Format:=wdTableFormatClassic2
'This example inserts numbers and text into the first column of the first table in the active document.
num = 90
For Each acell In ThisDoc.Tables(1).Columns(1).Cells
acell.Range.Text = num & " Sales"
num = num + 1
Next acell
-
Jan 10th, 2006, 11:49 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|