Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to save microsoft words document? 1

Status
Not open for further replies.

jonra

Programmer
Jul 20, 2003
42
SG
Public Function CreateWord(strDocuPath As String)

'function returns nothing, but I created this as a
'function so all those macro users out there could
'use it also. :p
'if no path is passed to function, exit - no further
'need to do anything

If IsNull(strDocuPath) Or strDocuPath = "" Then
Exit Function
End If

Dim dbs As Database
Dim objectWord As Object
Dim PrintResponse
Set dbs = CurrentDb

'create reference to Word Object

Set objectWord = CreateObject("Word.Application")

'Word Object is created - now let's fill it with data.

With objectWord
.Visible = True
.Documents.Open (strDocuPath)
'move to each bookmark, and insert correct text.
.ActiveDocument.Bookmarks("report").Select
.Selection.Text = (CStr(Forms!incident2!Report))
.ActiveDocument.Bookmarks("date").Select
.Selection.Text = (CStr(Forms!incident2!Date))
.ActiveDocument.Bookmarks("time").Select
.Selection.Text = (CStr(Forms!incident2!Time))
.ActiveDocument.Bookmarks("title").Select
.Selection.Text = (CStr(Forms!incident2!Title))
.ActiveDocument.Bookmarks("location").Select
.Selection.Text = (CStr(Forms!incident2!Location))

Range = Selection.Range
'** continue the ActiveDocument and Selection statements for each bookmark that you have on the Word Document **
Set objectWord = Nothing
End With
End Function



that is how i create it...i wan to save it so i can send the doc as attachment to email...i manage to send it...but the doc is empty...can anione help pls?thanks...
 
It's some time since I last did any work on Word, but the objWord object has a save method - so you simply need to find it

it may be

.SaveDocument

or

.Document.Save

but as I say, it's some time since I last did this, there are also numerouse parameters to say what format document etc, if you needed to save as anything other than word.
 
i found the solution in a book thanks anyway..
 
If you could post your solution, it may help others in the future, as a search would show not only your problem, but how you fixed it.

regards

John
 
any question bout the codes..pls feel free to ask..i will reply asap..

***********************************************************
Option Compare Database
Private m_objWord As Word.Application
Private m_objDoc As Word.Document

Public Sub CreateWord()
Dim m_strDIR As String
m_strDIR = "C:\Documents and Settings\Mr.Lim\My Documents\"
Dim dbs As Database
Set dbs = CurrentDb
Set m_objWord = New Word.Application
Set m_objDoc = m_objWord.Documents.Add("C:\Documents and Settings\Mr.Lim\My Documents\Template.dot")

insertTextAtBookMark "date", ("" & Forms!incident2!Date)
insertTextAtBookMark "title", ("" & Forms!incident2!Title)
insertTextAtBookMark "time", ("" & Forms!incident2!Time)
insertTextAtBookMark "location", ("" & Forms!incident2!Location)
insertTextAtBookMark "report", ("" & Forms!incident2!Report)

m_objDoc.SaveAs FileName:=m_strDIR & "Report - " & Forms!incident2!Title & ".DOC"

'm_objWord.PrintOut Background:=False

m_objDoc.Close
m_objWord.Quit
Set m_objDoc = Nothing
Set m_objWord = Nothing
End Sub

Private Sub insertTextAtBookMark(strBkmk As String, varText As Variant)
m_objDoc.Bookmarks(strBkmk).Select
m_objWord.Selection.Text = varText & ""

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top