954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Opening MS Word Docs in VB

Hi,
Does anyone know how to open a shared, read-only MS Word document in MS Word outside of the application upon clicking a command button?

Any help would be really appreciated
Many, many thanks

StephenHancox
Newbie Poster
6 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

You should be able to use some kind of control. I don't remember if there is a toolbox control for viewing office apps with VB or not.... you can also use scripting to do this.... but that will probably load word. There is a way though, using com objects.... I'll let you know if I find anything more.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

Try googling for OLE control and visual basic. Tons and tons of answers.

mnemtsas
Posting Whiz in Training
200 posts since Jul 2004
Reputation Points: 16
Solved Threads: 1
 

hi friend,

1. in project menu>refferences> select .. microsoft word 9.0 object library

Private Sub Command1_Click()

Dim objWord As Word.Application
' this would be faster with a "with objWord" but for clarity I use the explicit

Set objWord = New Word.Application
objWord.Visible = True
objWord.Documents.Open "c:\sql performance tips.doc", , , True

End Sub

first i though to give u a sample program. but now found a source which is providing info what i want to prepare. just go through it.
http://www.nigelrivett.net/PrintToWord.html

enjoy programming with vb ..all the best

srikanthvja
Newbie Poster
7 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

Hi there,
Many thanks for your recent help. The coding you provided worked amazingly. Will is still work if the document is password protected? Also the word documents I have are both a shared resource and password protected, will the code still work or will I need to code in the permissions/password?

many, many thanks

StephenHancox
Newbie Poster
6 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

hi,

to open password protected doc. we should know the password of the doc.
set file ->save as (select doc file)->tools > general options . . in pass word to open give pwd as sri, select readonly -. reenter pwd
the try this code.

Private Sub Command1_Click()

Dim objWord As Word.Application
' this would be faster with a "with objWord" but for clarity I use the explicit

Set objWord = New Word.Application
objWord.Visible = True
objWord.Documents.Open "c:\sql performance tips.doc", , , True, "sri"

End Sub

study about, open method parameters.

for more info go through
http://www.word.mvps.org/FAQs/MacrosVBA/CheckIfPWProtectB4Open.htm

note: please,if possible let me know how to set doc file share.i know how we have share a folder, but not a file.

enjoy vb programming... all the best

srikanthvja
Newbie Poster
7 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

Hi guys,

It is quite easy to open ms word document in vb6.

1. Include the "Microsoft Word 11.0 Object Library"
- version 11.0 for MS Office 2003 and 12.0 for MS Office 2007
2. Then put some command button or menu button to initiate the event:
e.g

Private Sub Command1_Click()
         Dim wrdApp As New Excel.Application
         wrdApp.Workbooks.Open App.Path & "Filename.doc"  
         wrdApp.WindowState = wdWindowStateMaximize
         wrdApp.Visible = True
       End Sub


Note: just change the "Filename" with your corresponding ms word doc file name.

Thants it!

Happy programming guys!


Jeff Sibal

jeff.sibal
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

@jeff.sibal thank you for your time writing this reply. However I would like to ask you that next time you check date of original post as like in this case, originally posted in 2005, original poster either already found solution or would not be interested in it after such a long time.
One more think I would like to ask you is to use code tags when you post any code, as [code]YOUR CODE HERE[/code]

Thank you and thread closed

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You