On May 19, 6:45*pm, xp <x...@newsgroup> wrote:
> Hi Tom,
>
> Thanks for the idea; however, I tried this and it didn't work...any other
> ideas?
>
> "Tom Lavedas" wrote:
> > On May 19, 10:05 am, xp <x...@newsgroup> wrote:
> > > I have both Office 2003 and 2007 dual installed on my PC.
> > > I need to point my script to open certain files using 2007, but it defaults
> > > to 2003.
> > > Can someone please help me out with this? How can I specify for the script
> > > to use 2007 when opening an Excel file? OK, the next best thing I can think of is to try forcing Excel2007 to
open and then load your file into it, something like this ...
' Next line needs to point to the location for your environment
sXLPath = """C:\Program Files\Microsoft Office\Office12\Excel.exe"" "_
& "/automation -Embedding"
sFilePath = "C:\Someplace\YourFileName.xls"
set oWSH = CreateObject("WScript.Shell")
nRes = oWSH.Run(sXLPath, 1, False)
if nRes <> 0 then
wsh.echo "Error opening Excel", nRes
wsh.quit
end if
On Error Resume Next
set oXL = GetObject("","Excel.Application")
if err.number <> 0 then
wsh.echo "Error opening Excel", hex(err.number), err.description
wsh.quit
end if
On Error Goto 0
oXL.visible = True
set oWkBk = oXL.WorkBooks.open(sFilePath)
' The rest of your script ...
oWkBk.Sheets(1).cells(1,1).value = "Done"
All of the documentation says that leaving the first argument empty
(i.e. GetObject( ,"Classname")) is supposed to attach to the running
object. However, on my XP machine, this approach is throwing a
runtime syntax error. So, I added an empty string, but I am assuming
that since Excel is a Single Instance application, the returned
automation object must be the 2007 object. As I said, I don't have it
to try. If I am correct, the Open() should then load the file into
the correct (2007) version of XL. It does work for the 2003 version I
was forced to test with.
Hope it works.
_____________________
Tom Lavedas