Click to See Complete Forum and Search --> : opening word doc
xxwhocaresxx
Jun 2nd, 2005, 01:08 PM
I am trying to open up a word document... and i keep getting an error,
here is my code
Dim oWord As Object
oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Document.Open(Application.StartupPath & "\QuickStartManual.doc")
Thanks!
sciguyryan
Jun 2nd, 2005, 01:25 PM
Tryb this:
Dim wdWord As Object
Dim wdDocument As Object
Set wdWord = CreateObject("Word.Application")
Set wdDocument = CreateObject("Word.Document")
Set wdDocument = wdWord.Documents.Open(wdWord.StartupPath & "\QuickStartManual.doc")
wdWord.Visible = True
Cheers,
RyanJ
zaza
Jun 2nd, 2005, 01:26 PM
Hi,
It's "Set oword = Createobject..."
zaza
EDIT: Rats. Beaten to it. :cry:
sciguyryan
Jun 2nd, 2005, 01:34 PM
Hi,
It's "Set oword = Createobject..."
zaza
EDIT: Rats. Beaten to it. :cry:
Sorry about that... It happens all the time to everyone (Me too ;))
Cheers,
RyanJ :)
xxwhocaresxx
Jun 2nd, 2005, 01:34 PM
whenever i type "Set" it disapears. i am still getting an error. any suggestions?
sciguyryan
Jun 2nd, 2005, 01:49 PM
whenever i type "Set" it disapears. i am still getting an error. any suggestions?
What error are you getting?
Cheers,
RyanJ
xxwhocaresxx
Jun 2nd, 2005, 01:53 PM
it breaks my code and it says:
"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occured in microsoft.visualbasic.dll"
i don't know if that helps any.
sciguyryan
Jun 2nd, 2005, 02:11 PM
it breaks my code and it says:
"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occured in microsoft.visualbasic.dll"
i don't know if that helps any.
I do not think that is to do with the VB code I gave you.
Are you using VB or VB.net?
Cheers,
RyanJ
xxwhocaresxx
Jun 2nd, 2005, 02:12 PM
i don't think its the code either, but i am not sure what might be causing that error.
i am using vb.net and word 2003
sciguyryan
Jun 2nd, 2005, 02:42 PM
i don't think its the code either, but i am not sure what might be causing that error.
i am using vb.net and word 2003
Ah, thought I had never seen that error in VB before.
You will havw to wait for the RobDog888 to have a look at this thread, I believe he knows VB.net and so should be able to help you :)
Cheers,
RyanJ
zaza
Jun 2nd, 2005, 03:14 PM
Hi,
Where does it give you that error? I thought VBA was VB6...unless it is because you're importing a control or library or something you've created in .Net. I suspect that this is more to do with that than to do with your VBA code.
:confused:
zaza
Ecniv
Jun 3rd, 2005, 02:52 AM
xxwhocaresxx i don't think its the code either, but i am not sure what might be causing that error.
i am using vb.net and word 2003
Perhaps a help file search for creating objects in .Net or maybe 'automation' ?
Edit:
Possibly helpful links?
MSDN site (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vsoriautomationextensibilityoverview.asp)
wossname
Jun 3rd, 2005, 03:23 AM
Listen up ppl. Firstly, don't post VB.Net questions in a VBA forum because it does my head in.
Set is no longer needed in .Net and the compiler ignores it and deletes it as soon as you try to use it.
xxwhocaresxx: have you added a reference to the relevant Word object library? You'll need to do that in order to create an instance of the word application.
For my outlook program i just used a reference to Interop.Office.dll and then this code to create an outlook app object...
Private OutApp As Outlook.ApplicationClass
............
OutApp = New Outlook.ApplicationClass
You should be able to figure out how to do the equivalent Word version for yourself.
wossname
Jun 3rd, 2005, 03:32 AM
To clarify the difference between the languages:
VBA = The village idiot. This guy is very slow witted and finds it hard to understand simple things.
VB6 = The family man, has 2.4 children and a labrador. Knows what he wants to do and does it his own way with little time for the new fangled methods. Reliable, gets the job done.
VB.Net = Extreme sports fanatic, control freak, slightly intense, irritable.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.