Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Open a specific Word document from an Excel Macro

I am trying to use Word documents for mail merges that differ depending upon
the state to which they will be sent. I currently select the state in an
Excel worksheet from a combo box that translates the state abbreviation to a
number from 1 to 50. I use a vlookup function to convert the chosen state to
the appropriate file and path name. I need to know how to use the results of
the vlookup cell to open the indicated Word document.
--
Confused, but learning.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Open a specific Word document from an Excel Macro

This is a GP macro for opening a word app and document, substitute your path
and filename where shown. You need to set a reference in Excel to the Word
Object Libary.

Sub OpenWord()
On Error GoTo errorHandler
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Set wordApp = New Word.Application
wordApp.Visible = True
wordApp.WindowState = wdWindowStateMaximize

Set wordDoc = wordApp.Documents.Open("C:\path\filename.doc")

wordApp.Quit
errorHandler:
Set wordApp = Nothing
Set wordDoc = Nothing
End Sub


--
Cheers
Nigel



"Canoeist" wrote in message
...
I am trying to use Word documents for mail merges that differ depending

upon
the state to which they will be sent. I currently select the state in an
Excel worksheet from a combo box that translates the state abbreviation to

a
number from 1 to 50. I use a vlookup function to convert the chosen state

to
the appropriate file and path name. I need to know how to use the results

of
the vlookup cell to open the indicated Word document.
--
Confused, but learning.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Open a specific Word document from an Excel Macro

Nigel,
Thanks much for your rapid response. Your answer doesn't do what I want it
to do, so I can only conclude that my question wasn't clear.

I have a cell in my excel worksheet that contains the file name I want to
open. I currently have a macro that opens Word with the statement:

Sub Open Word ()
Application.ActivateMicrosoftApp (x1MicrosoftWord)
End Sub

The results from my macro are unsatisfactory because word opens to a blank
document. Your macro requires me to include the Word document name and path
in the macro itself. What I would like is for the macro to pick up whatever
file name and path is currently in the cell. The cell entry is the result of
a lookup formula, since I have the user select one of fifty choices, each
having a related Word document. If it would help clarify the question, I
could include a sample Excel workbook.

Thanks


"Nigel" wrote:

This is a GP macro for opening a word app and document, substitute your path
and filename where shown. You need to set a reference in Excel to the Word
Object Libary.

Sub OpenWord()
On Error GoTo errorHandler
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Set wordApp = New Word.Application
wordApp.Visible = True
wordApp.WindowState = wdWindowStateMaximize

Set wordDoc = wordApp.Documents.Open("C:\path\filename.doc")

wordApp.Quit
errorHandler:
Set wordApp = Nothing
Set wordDoc = Nothing
End Sub


--
Cheers
Nigel



"Canoeist" wrote in message
...
I am trying to use Word documents for mail merges that differ depending

upon
the state to which they will be sent. I currently select the state in an
Excel worksheet from a combo box that translates the state abbreviation to

a
number from 1 to 50. I use a vlookup function to convert the chosen state

to
the appropriate file and path name. I need to know how to use the results

of
the vlookup cell to open the indicated Word document.
--
Confused, but learning.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Open a specific Word document from an Excel Macro

Substitute in the line that reads....

Set wordDoc = wordApp.Documents.Open("C:\path\filename.doc")

with

Set wordDoc = wordApp.Documents.Open(Range.("A1").value)

where A1 or (whatever) is the cell in which the path and filename resides.

or put a variable in and assign the cell to the variable eg

Dim myDoc as String
myDoc = Range("A1").value

then use (to open it)

Set wordDoc = wordApp.Documents.Open(myDoc)


--
Cheers
Nigel



"Canoeist" wrote in message
...
Nigel,
Thanks much for your rapid response. Your answer doesn't do what I want it
to do, so I can only conclude that my question wasn't clear.

I have a cell in my excel worksheet that contains the file name I want to
open. I currently have a macro that opens Word with the statement:

Sub Open Word ()
Application.ActivateMicrosoftApp (x1MicrosoftWord)
End Sub

The results from my macro are unsatisfactory because word opens to a blank
document. Your macro requires me to include the Word document name and

path
in the macro itself. What I would like is for the macro to pick up

whatever
file name and path is currently in the cell. The cell entry is the result

of
a lookup formula, since I have the user select one of fifty choices, each
having a related Word document. If it would help clarify the question, I
could include a sample Excel workbook.

Thanks


"Nigel" wrote:

This is a GP macro for opening a word app and document, substitute your

path
and filename where shown. You need to set a reference in Excel to the

Word
Object Libary.

Sub OpenWord()
On Error GoTo errorHandler
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Set wordApp = New Word.Application
wordApp.Visible = True
wordApp.WindowState = wdWindowStateMaximize

Set wordDoc = wordApp.Documents.Open("C:\path\filename.doc")

wordApp.Quit
errorHandler:
Set wordApp = Nothing
Set wordDoc = Nothing
End Sub


--
Cheers
Nigel



"Canoeist" wrote in message
...
I am trying to use Word documents for mail merges that differ

depending
upon
the state to which they will be sent. I currently select the state in

an
Excel worksheet from a combo box that translates the state

abbreviation to
a
number from 1 to 50. I use a vlookup function to convert the chosen

state
to
the appropriate file and path name. I need to know how to use the

results
of
the vlookup cell to open the indicated Word document.
--
Confused, but learning.






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
Macro to open specific document Thew21 Excel Discussion (Misc queries) 1 December 13th 06 01:18 PM
help creating a macro in excel that opens a specific word document Prohock Excel Discussion (Misc queries) 3 March 30th 06 04:58 PM
getting specific info from a word document into excel smintey Excel Discussion (Misc queries) 3 December 8th 04 08:20 PM
Opening Word with a specific document from excel vba JRB Excel Programming 5 October 22nd 04 02:11 PM
macro and button to open a word document from within excel JAJOSEPHESQ Excel Programming 1 May 5th 04 06:06 AM


All times are GMT +1. The time now is 11:47 AM.

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

About Us

"It's about Microsoft Excel"