What is wrong with my code?

A

Al

I am using Access 97. I am trying to do the following:
1) open an existing file in excle
2) insert a row on the top
3) fill in range A1:A4 with text
4) close excel

here is the code:
********************** Start ******************
Dim XL As Excel.Workbook,As String, strFile As String

strFile = "c:\InsTst.xls"
Call Shell("""C:\Program Files\Microsoft
Office\Office\EXCEL.EXE"" /automation", 1)
Set XL = GetObject(strFile, "Excel.Sheet")
XL.Application.Visible = True 'Make Excel
Visible.
XL.Application.Windows(strFile).Visible = True
Make the Workbook visible.
Worksheets("Sheet1").Rows(1).Insert
Range("A1") = "Subject"
Range("A2") = "usEquiv"
Range("A3") = "Level"
Range("A4") = "Grade"
XL.Application.Run "Save"
XL.Application.Quit
Set XL = Nothing
********************** End ******************

The code break on
XL.Application.Windows(strFile).Visible = True Make the
Workbook visible.

and it gives me script is out of range?
what is the wrong with my code and how can I accomplish
what I need in an easy way. thanks
Al
 
D

Douglas J. Steele

I think you'll find that the Windows are identified by only the file name,
not the full path.

See whether this works:

XL.Application.Windows(Dir(strFile)).Visible = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top