By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

How can I open a Word document from my VB application?

P: 3
Hi All,

As the title states - How can I open a Word document from my Visual Basic application?
Apr 10 '07 #1
Share this Question
Share on Google+
13 Replies


SammyB
Expert 100+
P: 807
Hi All,

As the title states - How can I open a Word document from my Visual Basic application?
Which Visual Basic? VB6, VBA, or VB.NET?
This thread has an example for VB.NET. It's easier in VBA & VB6. Let us know if that is what you want.
Apr 11 '07 #2

P: 3
Which Visual Basic? VB6, VBA, or VB.NET?
This thread has an example for VB.NET. It's easier in VBA & VB6. Let us know if that is what you want.
I am using Visual Basic 6
Apr 15 '07 #3

SammyB
Expert 100+
P: 807
I am using Visual Basic 6
You'll need to add a Reference to Microsoft Word Object Library (with the Tools, References menu, i think, no VB6 here). Code is easy:
Expand|Select|Wrap|Line Numbers
  1. Dim wrdApp As New Word.Application
  2.     wrdApp.Documents.Open "E:\My Documents\ReadMe.doc"
  3.     wrdApp.Visible = True
Apr 15 '07 #4

P: 3
Thanks for that. It worked like a dream!
Apr 20 '07 #5

P: 3
[quote=Mark H]Hi All,

How can I open a internet explorer from my VB application?
Apr 21 '07 #6

debasisdas
Expert 5K+
P: 8,127
u can also use a rich text box to open .RTF files

rtf1.loadfile(filepath)
Apr 21 '07 #7

P: 1
Hi i am trying to also open a word document up in VB6 and the code with the absolute path words great. However is there a way of opening a document with a relative path? I have simply just tried taking out the file path but it causes a runtime error. Its in the same file as my program. If I go to install the program on a machine i need to have a relative path or a way of placing the the new file path into the code. Can anyone help please?
Apr 28 '07 #8

SammyB
Expert 100+
P: 807
Hi i am trying to also open a word document up in VB6 and the code with the absolute path words great. However is there a way of opening a document with a relative path? I have simply just tried taking out the file path but it causes a runtime error. Its in the same file as my program. If I go to install the program on a machine i need to have a relative path or a way of placing the the new file path into the code. Can anyone help please?
If I remember correctly for VB6 (which is doubtful :(), you use Application.Path to get the starting path and then you concatinate the relative path to it. But, no VB6 until Monday to check it. Just look at the Application object (with intellisense, object browser, or help), I think it gives you the starting path that you want.
Apr 28 '07 #9

P: 1
Hi EveryOne!
How can I open a Word document from my VB.Net ?
Thanks!
May 18 '07 #10

SammyB
Expert 100+
P: 807
Hi EveryOne!
How can I open a Word document from my VB.Net ?
Thanks!
Take a look at http://www.thescripts.com/forum/post2506278-10.html. It's for C#, but that's a fairly easy translation. You won't need the ref ms parameters, VB does that for you.

You'll need to install Office Interop, http://msdn2.microsoft.com/en-us/lib...hw(vs.80).aspx

Found a better example, http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx, just pull out the Word code.

I'd give you a better example, but I do not have Interop installed here. If you have problems, post back. HTH --Sam
May 18 '07 #11

MiraKimura
P: 6
You'll need to add a Reference to Microsoft Word Object Library (with the Tools, References menu, i think, no VB6 here). Code is easy:
Expand|Select|Wrap|Line Numbers
  1. Dim wrdApp As New Word.Application
  2.     wrdApp.Documents.Open "E:\My Documents\ReadMe.doc"
  3.     wrdApp.Visible = True
how if there is error messagebox saying "user-defined type not defined" and poin to wrdApp As New Word.Application?

tq.
Oct 22 '07 #12

MiraKimura
P: 6
u can also use a rich text box to open .RTF files

rtf1.loadfile(filepath)
running this code, i get run-time error '75': The specified Path/file name cannot be accessed or invalid.

given the code:

rtHowTo.LoadFile (App.Path + "\howto.doc")

i used rich textbox name rtHowTo and i have put the howto doc file inside the same folder which i keep the system.

can anyone help me to view word file in VB?
Oct 22 '07 #13

MiraKimura
P: 6
how if there is error messagebox saying "user-defined type not defined" and poin to wrdApp As New Word.Application?

tq.
opps, sorry. i just know how to add references. but it is not in tool menu, but project menu.

'microsoft word 11.0 object library'. rite?

now, there is no more error, but the content of the file is not coming out. the richtextbox is empty. what should i do?
Oct 22 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.