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

Opening A Word Doc

P: 3
could someone please help me - I am trying to open a word document within my program from just the click of a command button (not using dialog boxes) could some one please give me the code for this as am sure its fairly simple.
Apr 17 '07 #1
Share this Question
Share on Google+
10 Replies


P: 63
Have you tried using the Shell command?
Apr 17 '07 #2

P: 4
this may work; it seems to work for everyone except for me


Dim oWord As Object

oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Open("\filename.doc")
Apr 17 '07 #3

P: 3
no I havent tried shell command - not sure how it works - but like that code above (havent tried yet ill get back on the outcome) is there not just simple code that will do the job?
thanks so far
Apr 17 '07 #4

SammyB
Expert 100+
P: 807
could someone please help me - I am trying to open a word document within my program from just the click of a command button (not using dialog boxes) could some one please give me the code for this as am sure its fairly simple.
To give the best answer, we need to know what VB are you using? VBA (what application), VB6, or VB.NET?
Apr 17 '07 #5

P: 3
To give the best answer, we need to know what VB are you using? VBA (what application), VB6, or VB.NET?
am using vb 6
Apr 18 '07 #6

SammyB
Expert 100+
P: 807
am using vb 6
Dude has the correct answer, but it would be better to use the Project, References menu to add a reference to Microsoft Word Object Library. Then,
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Sub Command2_Click()
  3.     Const WD_DOC As String = "N:\Programming\Word\WordTable\ReadMe.doc"
  4.     Dim wdApp As New Word.Application
  5.     Dim wdDoc As Word.Document
  6.     Set wdDoc = wdApp.Documents.Open(FileName:=WD_DOC)
  7.     wdApp.Visible = True
  8. End Sub
  9.  
  10.  
HTH --Sam
Apr 18 '07 #7

100+
P: 138
Dude has the correct answer, but it would be better to use the Project, References menu to add a reference to Microsoft Word Object Library. Then,
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Sub Command2_Click()
  3.     Const WD_DOC As String = "N:\Programming\Word\WordTable\ReadMe.doc"
  4.     Dim wdApp As New Word.Application
  5.     Dim wdDoc As Word.Document
  6.     Set wdDoc = wdApp.Documents.Open(FileName:=WD_DOC)
  7.     wdApp.Visible = True
  8. End Sub
  9.  
  10.  
HTH --Sam

hi ,
can we use the common dialog control to locate the file path instead of giving the direct path name in the 'Const WD_DOC as string="N:\.......\ReadMe.doc',
i used it but it doesn't open the file.
Apr 19 '07 #8

SammyB
Expert 100+
P: 807
hi ,
can we use the common dialog control to locate the file path instead of giving the direct path name in the 'Const WD_DOC as string="N:\.......\ReadMe.doc',
i used it but it doesn't open the file.
Yes & No -- Yes, use the common Dialog, but no, Common Dialog doesn't open the file: it only gets the filename, you still need to open the file with Documents.Open
Apr 19 '07 #9

P: 1
HELP.....

hi all...
i have problem about open doc too...
i ever try like source code that u r told.
but there is error mssg
"the speciefied module cannot be found"
i used reference "microsoft word 12.0 library"
i dont know when i type " set wrdapp= new word.application"
the program give that error...
please help..
i dont know how to solve this problem...
thx b4
:)
May 5 '07 #10

SammyB
Expert 100+
P: 807
HELP.....

hi all...
i have problem about open doc too...
i ever try like source code that u r told.
but there is error mssg
"the speciefied module cannot be found"
i used reference "microsoft word 12.0 library"
i dont know when i type " set wrdapp= new word.application"
the program give that error...
please help..
i dont know how to solve this problem...
thx b4
:)
What VB are you using? VBA (What Application?), VB6, or VB.NET
I suspect that you selected the reference, but did not place a checkmark in the box. (suspected because of the many times I've done it too ;) ) Reopen References and make sure Microsoft Word Library is checked.

You could also try it Dude's way, see above, it doesn't need a reference. hth --Sam
May 5 '07 #11

Post your reply

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