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

Hi I have a userform that collects all word doc from
directory into a list box, now I need to open a doc when
the user select one and write the user name to the Author
part can this be done in excel vba if so can someone help
please.
Frank.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Open a Word Document

On Thu, 5 Feb 2004 08:26:07 -0800, "Frank"
wrote:

Hi I have a userform that collects all word doc from
directory into a list box, now I need to open a doc when
the user select one and write the user name to the Author
part can this be done in excel vba if so can someone help
please.


You can call the following function to do that. (The function has been
tested, but is NOT bullet-proof. Error handling is rudimentary):

------------------------------------

Function OpenSelectedWordDocument _
(FullNameOfDoc As String, _
Optional AuthorName As String) As Boolean

Dim wdApp As Object
Dim wdDoc As Object

On Error GoTo ErrorHandler

OpenSelectedWordDocument = False

'Open a new instance of Word and make it
'visible.
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True

'Open the selected document, the name of which
'you have passed as an argument to this function.
'NB: I assume that your existing process confirms that
'this file exists.
Set wdDoc = wdApp.Documents.Open(Filename:=FullNameOfDoc)

'If no user name is passed to the function, use the one
'defined in Office.
If AuthorName = "" Then
wdDoc.BuiltinDocumentProperties("Author") _
= Application.UserName
Else
wdDoc.BuiltinDocumentProperties("Author") _
= AuthorName
End If

'Return value of the function; signifies successful completion.
OpenSelectedWordDocument = True

ExitPoint:

Set wdDoc = Nothing
Set wdApp = Nothing

Exit Function

ErrorHandler:
MsgBox "Sorry, unable to open the Word file. The following error
occurred:" _
& vbCrLf & Err.Number & vbCrLf & Err.Description

Resume ExitPoint

End Function

---------------------

The following example procedure shows how to run it. You'd probably do
that from a command button on your user form:

Sub TestOpen()

'You would pass the file name that your user has selected
'rather than a hard coded string, obviously.

OpenSelectedWordDocument _
"H:\Word_And_Documents\Tests_Development\TestDoc1. doc", "Hank S."

End Sub

---------------------------------------------------------
Hank Scorpio
scorpionet who hates spam is at iprimus.com.au (You know what to do.)
* Please keep all replies in this Newsgroup. Thanks! *
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 a new word document Ciara Excel Discussion (Misc queries) 1 May 18th 05 11:04 AM
what happens if I open an excel document in word? Emily Excel Discussion (Misc queries) 3 April 2nd 05 10:49 AM
open a new word document out of excel walt Excel Programming 0 August 11th 03 09:22 PM


All times are GMT +1. The time now is 01:49 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"