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
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
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
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]
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.
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" <anthony.white@citizensbank.com> wrote in message
news:7003AC2F-2E64-4F5E-807F-A4E921B1EAE3@microsoft.com...
> 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.
>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks