Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Shell function?

129 views
Skip to first unread message

Kevin Docherty

unread,
Jun 3, 2003, 5:01:30 AM6/3/03
to
Hi,

I have a worksheet with a command button. When clicking
this button, I want to open a Word document called
agenda.doc. I have used the shell function but this can
only open the application and not the specific filename.
What can I do in order to open other programmes within a
worksheet by clicking command buttons.

Thanks

Kevin

Hank Scorpio

unread,
Jun 3, 2003, 5:53:49 AM6/3/03
to

One way:

Private Sub CommandButton1_Click()

Dim obj As Object

Set obj = CreateObject("Word.Application")

obj.Visible = True

obj.Documents.Open "H:\EXCEL\Tests_Development\TestDocument.doc"

Set obj = Nothing

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! *

Graham S

unread,
Jun 3, 2003, 6:16:06 AM6/3/03
to
If you are automating the Word procedure
sub test()
Dim wdApp As Object

Set wdApp = CreateObject("Word.application")
Stop
'from here on you can issue MSWord macro commands
'but prefixed with "wdApp." (don't forget the dot after wdApp)
'commands not prefixed by "wdApp."
'will be directed to "Application" i.e. to Excel.Application
WdApp.Documents.Close 'should close all docs
Set wdApp = Nothing 'should end the application
end sub

If you just want to start the application and open a specific document for
the user to edit, the Shell function can do that I think
sub test2()
Dim Reply as variant
Reply = Shell("""C:\Program Files\Microsoft Office\Office\Winword.exe""
""DocPath\DocName.doc""", 1) '(this is all one line)
'The extra quotes permit spaces in the path or file names
Application.WindowState=xlMinimized 'get out of the way of word
end sub


HTH

Graham


"Kevin Docherty" <kevin.d...@centrica.co.uk> wrote in message
news:0cd801c329ae$b9688930$a101...@phx.gbl...

Hank Scorpio

unread,
Jun 4, 2003, 5:07:40 AM6/4/03
to
I have no idea why this post from last night apparently didn't make it
onto the server / Google (despite Agent showing success), but one more
try...

On Tue, 3 Jun 2003 11:16:06 +0100, "Graham S" <Gra...@nospam.net>
wrote:

>If you are automating the Word procedure
>sub test()
>Dim wdApp As Object
>
> Set wdApp = CreateObject("Word.application")

[Snip]


> Set wdApp = Nothing 'should end the application

Not quite. All that does is to clear the reference to the Word
application object from your variable. The application itself, once
started, will remain unaffected. To end the application, you would use
the application's Quit method:

wdApp.Quit

Graham S

unread,
Jun 4, 2003, 9:36:50 AM6/4/03
to
True, O King!
And I usually add "Set wdApp = Nothing" as well, just to be quite sure!
graham

"Hank Scorpio" <Apoll...@Hates.Spam> wrote in message
news:j6drdvgoull6vsrrh...@4ax.com...

0 new messages