Click to See Complete Forum and Search --> : Load a word document through VBA
computer_kid1
07-23-2004, 09:51 AM
I have an access database i have produced for someone so that they can read through contacts and be able to send them emails, texts or letters.
To be able to send a letter i need to create a command button that will load up a word document.
Does anyone know the coding (in VBA) to load the document???
Thanks for your help.
fishybawb
07-23-2004, 10:03 AM
http://www.techonthenet.com/access/modules/word_doc.htm
:t
computer_kid1
07-23-2004, 10:06 AM
thanks for that i will try it now.
i searched round google but could find one that worked.
fishybawb
07-23-2004, 10:08 AM
Post back if it doesn't work, there are some people around here who actually know VBA (unlike me ;) ) - you just have to wait for them to turn up.
computer_kid1
07-23-2004, 10:19 AM
The code given by fishybawb works until the point highlighed.
Private Sub Command1_Click()
Dim LWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "C:\Documents and Settings\David Southey\My Documents\Dave\School\It\Project 2\destiny\send letter.doc"
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open filename:=LWordDoc <-<<-<<---<<---- here
End If
End Sub
do you know what is wrong with this line?
i have also put in my edited version of the file directory.
ScaryBinary
07-23-2004, 11:53 AM
What error are you getting, and what version of Office (Word and Access) are you using?
It worked on my Office 2000 files.
computer_kid1
07-24-2004, 06:09 AM
Yesterday it froze and when i checked the tak manager it sad that word had stopped responding so i ended it then debugged the vba script. It stopped at that line with an error but i cant remember what it was.
The strange thing is that I restarted the PC and it did the same thing. But today when i came to try to solve it it worked fine.
I am using Office 2000.
It is now working fine thanks guys. The only slight problem is that it takes about 10 seconds to load up. Is there a possible way to speed this up or not??
ScaryBinary
07-24-2004, 08:10 AM
I don't know....I think it just depends on how long it takes Word to open, and how big your document is.
SysOpt.com
Copyright Internet.com Inc. All Rights Reserved.