Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   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 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"