473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calling excel: subscript out of range

EJO
In my app (A2k), I have the following code, which opens the file, but
also brings up a pop-up which states the "subscript is out of range":

Dim objXL As Object
Dim objWkb As Object
Dim objSht As Object
Dim SRval, OLDir, Ver, filePath, fileList, CountVer

Const OLInfo = "OL Template"
Set objXL = GetObject("", "Excel.Application")

SRval = Left(Me!SR, Len(Me!SR) - 4)
OLDir = "\\oflnmoejfs1\shares\eol\" & SRval & "0000-" & SRval &
"9999\"
fileList = OLDir & Me!SR & "V?.xls"
CountVer = Dir(fileList)

Do Until CountVer = ""
Ver = Ver + 1
CountVer = Dir()
Loop

filePath = OLDir & Me!SR & "V" & Ver & ".xls"
With objXL
.Visible = True
Set objWkb = .Workbooks.Open(filePath)
Set objSht = objWkb.Worksheets(OLInfo)
End With
It is worthy to note that this is also used in another place, which
results without opening a file, but oddly, no error (the file exists).
I believe the problem is with the Do Until Loop. I changed this code
from calling excel.exe directly instead of the api(?), and that is when
the problems popped up. Previously, I was calling XL and the file as
you would on a command line. All my references are still intact.
Tryin to learn--really!

Thanks for the help!

Eric

Nov 13 '05 #1
2 4885
"EJO" <5p****@centurytel.net> wrote in news:1118421980.669751.147380
@g43g2000cwa.googlegroups.com:
In my app (A2k), I have the following code, which opens the file, but
also brings up a pop-up which states the "subscript is out of range":

Dim objXL As Object
Dim objWkb As Object
Dim objSht As Object
Dim SRval, OLDir, Ver, filePath, fileList, CountVer

Const OLInfo = "OL Template"
Set objXL = GetObject("", "Excel.Application")

SRval = Left(Me!SR, Len(Me!SR) - 4)
OLDir = "\\oflnmoejfs1\shares\eol\" & SRval & "0000-" & SRval &
"9999\"
fileList = OLDir & Me!SR & "V?.xls"
CountVer = Dir(fileList)

Do Until CountVer = ""
Ver = Ver + 1
CountVer = Dir()
Loop

filePath = OLDir & Me!SR & "V" & Ver & ".xls"
With objXL
.Visible = True
Set objWkb = .Workbooks.Open(filePath)
Set objSht = objWkb.Worksheets(OLInfo)
End With
It is worthy to note that this is also used in another place, which
results without opening a file, but oddly, no error (the file exists).
I believe the problem is with the Do Until Loop. I changed this code
from calling excel.exe directly instead of the api(?), and that is when
the problems popped up. Previously, I was calling XL and the file as
you would on a command line. All my references are still intact.
Tryin to learn--really!

Thanks for the help!

Eric


The workbook you are trying to open that invokes the error doesn't have a
sheet named "OL Template".
Nov 13 '05 #2
EJO
Thanks, Corey. No, the only thing that has changed is the means by
which excel is being called. To be sure, I checked, and the excel file
still has a sheet tab "OL Template". I eventually got this to
work--don't know how, though, but am thinking I had a typo that i
unknowingly corrected.

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: BerkshireGuy | last post by:
I am writing an Module in Access 2000 that needs to reference an opened Excel Workbook. Lets say the workbook is called Rankings. How would I reference that workbook from within Access? Thanks
3
by: Nick Douglas | last post by:
Hello, I'd like to programmatically reference the Excel Object Library from an Access form using VB. I am using this code: Application.VBE.vbprojects("VBAProject").References.AddFromFile...
3
by: Mike Fellows | last post by:
i have some code that pulls a large amount of data from a database and puts it into an excel spreadsheet, some excel formulas are inserted and the whole lot gets printed out (excel in invisble...
51
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
1
by: Kathy | last post by:
I have a number of reports in a MS Access application that have a logo picture embedded in the report. When I run the report and choose File, then Export to Excel, I get an error indicating...
2
by: Brian Parker | last post by:
I need to format text in cell in an Excel worksheet and I need to do this using C#. I've seen code that will set the format for the whole cell, but I just need to format one character in that...
6
by: josh | last post by:
Hi I've a dubt! when we have overloaded functions the compiler chooses the right being based on the argument lists...but when we have two subscript overloaded functions it resolves them being...
1
by: MarkDotNet | last post by:
Hi I am trying to switch Excel worksheets in VBA. I get an error saying "subscript out of range". Please Help- Here is code (Fails on last 2 lines- Note that I ommited the recordset portion of...
1
by: rweston | last post by:
I am trying to open an MS Excel file and perform a find/replace function, all using VBA within MS Access. I keep getting a "Subscript out of range." error. Do you know why I am getting this error? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.