Working with Word template

P

Pallavi Kulkarni.

Hello,
I want to create template and after adding values to bookmark i want to
create word doc..but as this is a web application i dont want to save
resultant doc file on server..so is there any way by which i can create
stream of doc contents and if want download them...
Even i wnt to know how to close WinWord process in blow written code

Private Sub Command1_Click()
Dim wrdApp As Word.Application
Dim curDoc As Document
Dim newDoc As Document
Dim str As String
Dim bm As Bookmark
Dim i As Integer

Set wrdApp = New Word.Application
wrdApp.Visible = False
wrdApp.Documents.Open "F:\WordWrite\Name.dot"
str = ""
Set curDoc = wrdApp.ActiveDocument

For i = 1 To curDoc.Bookmarks.Count
curDoc.Bookmarks(i).Range.Text = "Pallavi"
Next i

Word.ActiveDocument.SaveAs "F:\WordWrite\done1.doc"
Word.ActiveDocument.Close
End Sub
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Palluvi:

You've posted this question in the wrong group (Sorry: it's easy to do that
the way they set up the Web interface... This is the Macintosh Word group).
You need to ask again in the VBA group, so I have cross-posted this reply
for you.

Basically, you need to "Set wrdApp = Nothing" at the end of your code to
close the application. But I am also worried that your last two lines are
addressing "Word.ActiveDocument". I think that should be "wrdApp", so you
do not potentially get two instances of the application. You can't use
"ActiveDocument" with "wrdApp" once you set Visible = False, because if the
instance is not visible, none of its documents can be "active".

Hope this helps

Hello,
I want to create template and after adding values to bookmark i want to
create word doc..but as this is a web application i dont want to save
resultant doc file on server..so is there any way by which i can create
stream of doc contents and if want download them...
Even i wnt to know how to close WinWord process in blow written code

Private Sub Command1_Click()
Dim wrdApp As Word.Application
Dim curDoc As Document
Dim newDoc As Document
Dim str As String
Dim bm As Bookmark
Dim i As Integer

Set wrdApp = New Word.Application
wrdApp.Visible = False
wrdApp.Documents.Open "F:\WordWrite\Name.dot"
str = ""
Set curDoc = wrdApp.ActiveDocument

For i = 1 To curDoc.Bookmarks.Count
curDoc.Bookmarks(i).Range.Text = "Pallavi"
Next i

Word.ActiveDocument.SaveAs "F:\WordWrite\done1.doc"
Word.ActiveDocument.Close
End Sub

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top