• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How do i open Excel 2003 or 2007 from VBS

R
#1
I have both 2003 and 2007 installed on my machine. I want to create a VB
Script to open a few files in 2003 and in 2007 versions. How can i do that?
 

My Computer

R

Richard Mueller [MVP]

#2
"RedV" <RedV@newsgroup> wrote in message
news:860341B7-8D6F-4227-8361-F6135080CDA1@newsgroup

>I have both 2003 and 2007 installed on my machine. I want to create a VB
> Script to open a few files in 2003 and in 2007 versions. How can i do
> that?
VBScript code similar to below should work for either version, as long as
the 2007 version is installed on the computer where you run the script:
=============
Option Explicit
Dim objExcel, objWorkbook

Set objExcel = CreateObject("Excel.Application")

' Open either 2003 or 2007 version Excel spreadsheet.
' objExcel.Workbooks.Open "C:\Scripts\Example.xls"
objExcel.Workbooks.Open "C:\Scripts\Example.xlsx"

Set objWorkbook = objExcel.ActiveWorkbook.Worksheets(1)

' Display some specific cell values.
Wscript.Echo objWorkbook.Cells(1, 1).Value
Wscript.Echo objWorkbook.Cells(1, 2).Value
Wscript.Echo objWorkbook.Cells(2, 1).Value
Wscript.Echo objWorkbook.Cells(2, 2).Value

' Clean up.
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)