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

I need to open a Word document from Excel. I know how to start Word but have
been unable to find the syntax for specifying a document at open. Can anyone
help?
Thanks,
Will
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Open A Word Document from Excel

Locate an un-used cell
Pull-down Insert Hyperlink
Set the hyperlink to point to the Word Document you want to open

Simply click on the link and your in business!!
--
Gary''s Student


"roadkill" wrote:

I need to open a Word document from Excel. I know how to start Word but have
been unable to find the syntax for specifying a document at open. Can anyone
help?
Thanks,
Will

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Open A Word Document from Excel

Hi roadkill,

roadkill wrote:
I need to open a Word document from Excel. I know how to start Word
but have been unable to find the syntax for specifying a document at
open. Can anyone help?


If you're looking for a programmatic solution, you have a few options.
First, you could automate Word and open the document from the automated
instance of the app. Or you could use the ShellExecute API function to
allow Windows to find the associated app and open the document. Here's an
example of the latter option (it will work for any file whose extension has
a registered app):

Public Const SW_SHOW = 5

Public Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Public Function gbOpenDocInDefaultApp(rsFullPath _
As String) As Boolean
gbOpenDocInDefaultApp = (ShellExecute(Application.hwnd, _
"open" & vbNullChar, rsFullPath & vbNullChar, vbNull, _
vbNullChar, SW_SHOW) 32)
End Function

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Open A Word Document from Excel

Ok here is a solution to open word in excel


Sub OpenWord()

'In the references add Microsoft Word 10.0 or whatever your current version
Dim wdApp As Word.Application
Dim myFilename As String

On Error Resume Next

Set wdApp = GetObject(, "Word.Application")

'Sometimes this fails. If it fails do this
If wdApp Is Nothing Then
Set wdApp = GetObject("", "Word.Application")
End If
On Error GoTo 0

myFilename = "insert path here"
myFilename = myFilename & strFilename


With wdApp
.Documents.Open Filename:=myFilename
'Make sure you set the visible property or the file will open but you won't
see it
.Visible = True
End With

Set wdApp = Nothing
End Sub

Notes: Depending on where the word document is located, you may want to put
a status bar on the application so the user knows the file is opening. This
will involve some extra coding and the subroutine above would call the status
bar procedure a few times. I am not referring to the Excel status bar but a
userform created to be a status bar. If you need help creating it, reply here
and I'll give you the code.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Open A Word Document from Excel

here is what I do so that I don't have version dependancies

'Module Level Code
Public Function OpenDocument(FileName As String, WordApp As Object) As
Object

'Open a word document template as a new document.

On Error GoTo MyErr

Set OpenDocument = WordApp.Documents.Add(Template:= _
FileName, NewTemplate _
:=False, DocumentType:=0)

Exit Function

MyErr:
MsgBox "Unable to open Application Template. " & Err.Description
Err.Clear
Exit Function

End Function

'Code to get is started

Dim objWord As Object
Dim objDoc As Object

Set objWord = CreateObject("Word.Application")
If Not objWord Is Nothing Then

Set objDoc = OpenDocument(<somepathtotemplate, objWord)

...do some processing...

objDoc.SaveAs FileName:= _
<somefilename, _
FileFormat:=0, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="",
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, _
SaveFormsData:=False, SaveAsAOCELetter:=False

End If
objWord.Quit
Set objWord = Nothing

"Tony White" wrote in message
...
Ok here is a solution to open word in excel


Sub OpenWord()

'In the references add Microsoft Word 10.0 or whatever your current
version
Dim wdApp As Word.Application
Dim myFilename As String

On Error Resume Next

Set wdApp = GetObject(, "Word.Application")

'Sometimes this fails. If it fails do this
If wdApp Is Nothing Then
Set wdApp = GetObject("", "Word.Application")
End If
On Error GoTo 0

myFilename = "insert path here"
myFilename = myFilename & strFilename


With wdApp
.Documents.Open Filename:=myFilename
'Make sure you set the visible property or the file will open but you
won't
see it
.Visible = True
End With

Set wdApp = Nothing
End Sub

Notes: Depending on where the word document is located, you may want to
put
a status bar on the application so the user knows the file is opening.
This
will involve some extra coding and the subroutine above would call the
status
bar procedure a few times. I am not referring to the Excel status bar but
a
userform created to be a status bar. If you need help creating it, reply
here
and I'll give you the code.





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
what happens if I open an excel document in word? Emily Excel Discussion (Misc queries) 3 April 2nd 05 10:49 AM
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 word document in excel Herb[_4_] Excel Programming 1 August 9th 03 01:36 AM


All times are GMT +1. The time now is 12:33 AM.

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"