Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Open Word Document using VBA in Excel

In Excel & Word - 2002
All I am looking for is a simple VBA code to open a specific word document.
Something like:

Sub OpenDOC1()
Documents.Open ("C:\DOC1.doc")
EndSub()

I know there is more to VBA code than that, but this is the bare bones idea
of what I need.

Instead of having Users memorize many document path names on a shared drive
to access them, I have created a Excel worksheet "Control Panel", where Users
can use drop-down boxes to select from multiple document choices. (I think
this format could work in both Excel and Word tables importing excel data, so
my question isn't Excel-specific)

A user will pull down a drop down box in Excel, choose between DOC-1, DOC-2,
DOC-3. When the User selects the document name, then VBA code will open that
document in word. I found VBA to perform that operation; the VBA code needs
to call in another VBA macro that opens that specific word document, which is
why I need the code for how to open a specific doc.

ELSE: am I making this too confusing for myself? Would a function work
better for that? I really want to stick to the drop-down box format, it is
the most user-friendly option in my case.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Open Word Document using VBA in Excel


Something like the following.
Note that it opens a separate instance of Word, even if one is already open.
'--
Sub OpenWordDocumentFromExcel()
On Error GoTo BadShow
Dim oWord As Object
Set oWord = CreateObject("Word.application")
oWord.Documents.Open "C:\Documents and Settings\Text Docs\HENRY V.doc"
oWord.Visible = True
AppActivate oWord
Set oWord = Nothing
Exit Sub
BadShow:
oWord.Quit
Set oWord = Nothing
End Sub
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"mokshadavid"

wrote in message
In Excel & Word - 2002
All I am looking for is a simple VBA code to open a specific word document.
Something like:

Sub OpenDOC1()
Documents.Open ("C:\DOC1.doc")
EndSub()

I know there is more to VBA code than that, but this is the bare bones idea
of what I need.
Instead of having Users memorize many document path names on a shared drive
to access them, I have created a Excel worksheet "Control Panel", where Users
can use drop-down boxes to select from multiple document choices. (I think
this format could work in both Excel and Word tables importing excel data, so
my question isn't Excel-specific)
A user will pull down a drop down box in Excel, choose between DOC-1, DOC-2,
DOC-3. When the User selects the document name, then VBA code will open that
document in word. I found VBA to perform that operation; the VBA code needs
to call in another VBA macro that opens that specific word document, which is
why I need the code for how to open a specific doc.
ELSE: am I making this too confusing for myself? Would a function work
better for that? I really want to stick to the drop-down box format, it is
the most user-friendly option in my case.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Open Word Document using VBA in Excel

Thanks, so much for your answer. I used only part of the code. When I
tested all of the code you gave me, it would open up the document and then
close it immediately. Why is this?

Sub OpenWordDocumentFromExcel()
Dim oWord As Object
Set oWord = CreateObject("Word.application")
oWord.Documents.Open "C:\test"
oWord.Visible = True
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Open Word Document using VBA in Excel


Probably, because of the error handling in the code.
If an error is generated then it closes word.
An error would be generated (for instance) if the file "C:\Test" did not exist.
It's your call.

Note: when controlling another application from Excel,
you should always set object references to nothing when exiting the sub...
"Set oWord = Nothing"
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"mokshadavid"
wrote in message
Thanks, so much for your answer. I used only part of the code. When I
tested all of the code you gave me, it would open up the document and then
close it immediately. Why is this?

Sub OpenWordDocumentFromExcel()
Dim oWord As Object
Set oWord = CreateObject("Word.application")
oWord.Documents.Open "C:\test"
oWord.Visible = True
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Open Word Document using VBA in Excel

Thanks, you answered my question. I hope anybody looking for how to Open a
microsoft word document with a Macro, VBA, or Function, will find your answer
post when searching. It helped me alot.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Open Word Document using VBA in Excel


You are welcome.
'--
Jim Cone
Portland, Oregon



"mokshadavid"

wrote in message
Thanks, you answered my question. I hope anybody looking for how to Open a
microsoft word document with a Macro, VBA, or Function, will find your answer
post when searching. It helped me alot.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
open word document in excel spaceslime Excel Discussion (Misc queries) 1 August 13th 05 03:15 PM
open up a word document in excel [email protected] Excel Programming 1 December 23rd 04 04:43 PM
Open a word document in excel Michael[_29_] Excel Programming 1 March 2nd 04 09:58 PM
open a new word document out of excel walt Excel Programming 0 August 11th 03 09:22 PM
open a word document in excel Herb[_4_] Excel Programming 1 August 9th 03 01:36 AM


All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"