View Full Version : Solved: Opening Path error?

08-02-2006, 12:33 AM
From within an Outlook VBAProject I need to Open a Word Document. The following code is fine;

strInvoice = "C:\Invoice1.doc"
RetVal = Shell("C:\Program Files\Microsoft Office\Office12\winword.exe" & strInvoice, 1)

But if;

strInvoice = "C:\Documents and Settings\Peter R Hawkes\Invoice1.doc"

Then Word opens but message states cannot find c:\documents.doc :banghead:

There has to be an easy answer but what is it!! I can see it is the spaces in the path but these cannot be changed?

Peter H

08-02-2006, 08:17 AM
Try changing it to this:

strInvoice = "Invoice1.doc"
RetVal = Shell("C:\Program Files\Microsoft Office\Office12\winword.exe\" & strInvoice, 1)

I had similar problems with paths and never could figure it out, so maybe that won't work, but I think it might.

08-02-2006, 08:29 AM
Unfortunately that will not find the file as there is no path information?

Peter H

08-04-2006, 12:24 AM
I don't understand why you are using Shell to do this. If you want to open a Word document from Outlook, make an instance of Word, and open the document.

Shell is going to open winword.exe anyway, so why not just explicitly use an instance of Word??

08-04-2006, 12:41 AM
You are quite correct and a lapse on my part as already using Word object to writ eto the invoice! After some help from Sue Mosher and a KB article I have settled on this:

Sub OpenInvoice(strOpenThis)

' http://support.microsoft.com/kb/177097/en-us
Dim wObj As Word.Application

On Error Resume Next
Set wObj = GetObject(, "Word.Application")
If Err <> 0 Then
Set wObj = CreateObject("Word.Application")
End If

wObj.Documents.Open (strOpenThis)
wObj.Visible = True
Set wObj = Nothing

End Sub

Thank you.

Peter H

08-05-2006, 06:20 AM
And there you go. Although make sure you quit and close the instance properly.....