473,383 Members | 1,978 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,383 software developers and data experts.

Excel opens readonly (sadly enough :)

Hello all,
As one of a few ways to let a user bring in data into my database I have
made 3 excel files.
Once the data are in the excel files my program checks if a required value
(Taal (Dutch) meaning Language) has been brought in. This value can only
have one of two values : N (for Nederlands - Dutch) and E (for English)
If a language in the excel has not been put in, the prog displays a warning.
After clicking the OK button of the msgbox the prog opens the excel file in
question, so allowing the user to correct the program. All works fine exept
for the fact that -when trying to save the corrected excel file I get a
warning that the file is (or has been opened) readonly. As you can see
below, I tried to solve the problem assigning the value FALSE to the
readonly property of the excelfile.
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile1.XLS", , False)
However I keep on getting the same readonly message. Can anybody tell me
what I am doing wrong here?
Many thanks...
Ronny
Dim ObjXL As Excel.Application
Dim ObjXLBook As Excel.Workbook
Dim ObjXLSheet As Excel.Worksheet
Set ObjXL = CreateObject("Excel.Application")
Dim teller As Integer, nAantalImport As Integer, sXlsName As String
Dim NoGo As Boolean
NoGo = True
teller = 1
Do While teller < 4 'LOOP TO DO THE SAME OPERATION ON THE 3 EXCEL FILES
nRow = 3
Select Case teller
Case 1
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile1.XLS", ,
False)
sXlsName = "Targets"
Case 2
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile2.XLS", ,
False)
sXlsName = "TargetMerchants"
Case 3
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile3.XLS", ,
False)
sXlsName = "TargetAffinityGroups"
End Select
Set ObjXLSheet = ObjXLBook.Worksheets("Main")

Do While Len(Nz(Trim(ObjXL.Cells(nRow, nEmailadres).Value))) > 1
If Nz(Trim(ObjXL.Cells(nRow, nTaal).Value)) = "N" Or _ 'CHECK FOR
THE EXISTANCE OF THE LANGUAGE IN THE EXCEL FILE
Nz(Trim(ObjXL.Cells(nRow, nTaal).Value)) = "E" Then
NoGo = False
Else
DoCmd.Hourglass False
NoGo = True
MsgBox ("In het Excel bestand m.b.t. tot de " & sXlsName & _
vbCrLf & "werd een taal niet correct ingevuld.. Gelieve dit
probleem" & vbCrLf & _
"eerst te corrigeren.")
Exit Do
Set rst = Nothing
Set dbsMybase = Nothing
Set ObjXLSheet = Nothing
Set ObjXLBook = Nothing
Set ObjXL = Nothing
End If
nRow = nRow + 1
Loop
If NoGo = True Then
Set ObjXL = CreateObject("Excel.Application")
Select Case teller 'REOPEN THE EXCEL FILE TO LET THE USER
CORRECT THE PROBLEM
Case 1
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile1.XLS", ,
False)
Case 2
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile2.XLS", ,
False)
Case 3
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile3.XLS", ,
False)
End Select
Set ObjXLSheet = ObjXLBook.Worksheets("Main")
ObjXL.Visible = True
Exit Do
End If
teller = teller + 1
Loop
Nov 12 '05 #1
2 4158
Your Excel workbook is still open from your first try at reading the data.
You must explicitly close the workbook
ObjXLBook.Close
before you can re-open it.
You also need to quit Excel
ObjXL.Quit
Otherwise, if you look in your task manager, you'll see multiple copies of
Excel running.
After about half a dozen, your application will refuse to open any more
copies.
Setting these objects = Nothing is not enough.

On the other hand, why bother to close and re-open everything?
You can save all that for after your
If NoGo = True Then
...
End If
and do it just once.

HTH
- Turtle
"Ronny Sigo" <ro********@skyynet.be> wrote in message
news:40***********************@news.skynet.be...
Hello all,
As one of a few ways to let a user bring in data into my database I have
made 3 excel files.
Once the data are in the excel files my program checks if a required value
(Taal (Dutch) meaning Language) has been brought in. This value can only
have one of two values : N (for Nederlands - Dutch) and E (for English)
If a language in the excel has not been put in, the prog displays a warning. After clicking the OK button of the msgbox the prog opens the excel file in question, so allowing the user to correct the program. All works fine exept for the fact that -when trying to save the corrected excel file I get a
warning that the file is (or has been opened) readonly. As you can see
below, I tried to solve the problem assigning the value FALSE to the
readonly property of the excelfile.
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile1.XLS", , False)
However I keep on getting the same readonly message. Can anybody tell me
what I am doing wrong here?
Many thanks...
Ronny
Dim ObjXL As Excel.Application
Dim ObjXLBook As Excel.Workbook
Dim ObjXLSheet As Excel.Worksheet
Set ObjXL = CreateObject("Excel.Application")
Dim teller As Integer, nAantalImport As Integer, sXlsName As String
Dim NoGo As Boolean
NoGo = True
teller = 1
Do While teller < 4 'LOOP TO DO THE SAME OPERATION ON THE 3 EXCEL FILES
nRow = 3
Select Case teller
Case 1
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile1.XLS", ,
False)
sXlsName = "Targets"
Case 2
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile2.XLS", ,
False)
sXlsName = "TargetMerchants"
Case 3
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile3.XLS", ,
False)
sXlsName = "TargetAffinityGroups"
End Select
Set ObjXLSheet = ObjXLBook.Worksheets("Main")

Do While Len(Nz(Trim(ObjXL.Cells(nRow, nEmailadres).Value))) > 1
If Nz(Trim(ObjXL.Cells(nRow, nTaal).Value)) = "N" Or _ 'CHECK FOR
THE EXISTANCE OF THE LANGUAGE IN THE EXCEL FILE
Nz(Trim(ObjXL.Cells(nRow, nTaal).Value)) = "E" Then
NoGo = False
Else
DoCmd.Hourglass False
NoGo = True
MsgBox ("In het Excel bestand m.b.t. tot de " & sXlsName & _
vbCrLf & "werd een taal niet correct ingevuld.. Gelieve dit
probleem" & vbCrLf & _
"eerst te corrigeren.")
Exit Do
Set rst = Nothing
Set dbsMybase = Nothing
Set ObjXLSheet = Nothing
Set ObjXLBook = Nothing
Set ObjXL = Nothing
End If
nRow = nRow + 1
Loop
If NoGo = True Then
Set ObjXL = CreateObject("Excel.Application")
Select Case teller 'REOPEN THE EXCEL FILE TO LET THE USER
CORRECT THE PROBLEM
Case 1
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile1.XLS", , False)
Case 2
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile2.XLS", , False)
Case 3
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile3.XLS", , False)
End Select
Set ObjXLSheet = ObjXLBook.Worksheets("Main")
ObjXL.Visible = True
Exit Do
End If
teller = teller + 1
Loop

Nov 12 '05 #2
Thank you very much, you saved my day :)

Ronny

"MacDermott" <ma********@nospam.com> schreef in bericht
news:%Y*****************@newsread3.news.atl.earthl ink.net...
Your Excel workbook is still open from your first try at reading the data.
You must explicitly close the workbook
ObjXLBook.Close
before you can re-open it.
You also need to quit Excel
ObjXL.Quit
Otherwise, if you look in your task manager, you'll see multiple copies of
Excel running.
After about half a dozen, your application will refuse to open any more
copies.
Setting these objects = Nothing is not enough.

On the other hand, why bother to close and re-open everything?
You can save all that for after your
If NoGo = True Then
...
End If
and do it just once.

HTH
- Turtle
"Ronny Sigo" <ro********@skyynet.be> wrote in message
news:40***********************@news.skynet.be...
Hello all,
As one of a few ways to let a user bring in data into my database I have
made 3 excel files.
Once the data are in the excel files my program checks if a required value (Taal (Dutch) meaning Language) has been brought in. This value can only
have one of two values : N (for Nederlands - Dutch) and E (for English)
If a language in the excel has not been put in, the prog displays a warning.
After clicking the OK button of the msgbox the prog opens the excel file

in
question, so allowing the user to correct the program. All works fine

exept
for the fact that -when trying to save the corrected excel file I get a
warning that the file is (or has been opened) readonly. As you can see
below, I tried to solve the problem assigning the value FALSE to the
readonly property of the excelfile.
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile1.XLS", , False)
However I keep on getting the same readonly message. Can anybody tell me
what I am doing wrong here?
Many thanks...
Ronny
Dim ObjXL As Excel.Application
Dim ObjXLBook As Excel.Workbook
Dim ObjXLSheet As Excel.Worksheet
Set ObjXL = CreateObject("Excel.Application")
Dim teller As Integer, nAantalImport As Integer, sXlsName As String
Dim NoGo As Boolean
NoGo = True
teller = 1
Do While teller < 4 'LOOP TO DO THE SAME OPERATION ON THE 3 EXCEL FILES
nRow = 3
Select Case teller
Case 1
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile1.XLS", ,
False)
sXlsName = "Targets"
Case 2
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile2.XLS", ,
False)
sXlsName = "TargetMerchants"
Case 3
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\MyFile3.XLS", ,
False)
sXlsName = "TargetAffinityGroups"
End Select
Set ObjXLSheet = ObjXLBook.Worksheets("Main")

Do While Len(Nz(Trim(ObjXL.Cells(nRow, nEmailadres).Value))) > 1
If Nz(Trim(ObjXL.Cells(nRow, nTaal).Value)) = "N" Or _ 'CHECK FOR THE EXISTANCE OF THE LANGUAGE IN THE EXCEL FILE
Nz(Trim(ObjXL.Cells(nRow, nTaal).Value)) = "E" Then
NoGo = False
Else
DoCmd.Hourglass False
NoGo = True
MsgBox ("In het Excel bestand m.b.t. tot de " & sXlsName & _
vbCrLf & "werd een taal niet correct ingevuld.. Gelieve dit
probleem" & vbCrLf & _
"eerst te corrigeren.")
Exit Do
Set rst = Nothing
Set dbsMybase = Nothing
Set ObjXLSheet = Nothing
Set ObjXLBook = Nothing
Set ObjXL = Nothing
End If
nRow = nRow + 1
Loop
If NoGo = True Then
Set ObjXL = CreateObject("Excel.Application")
Select Case teller 'REOPEN THE EXCEL FILE TO LET THE USER
CORRECT THE PROBLEM
Case 1
Set ObjXLBook =

ObjXL.Workbooks.Open("MyPath\MyFile1.XLS", ,
False)
Case 2
Set ObjXLBook =
ObjXL.Workbooks.Open("MyPath\MyFile2.XLS", ,
False)
Case 3
Set ObjXLBook =
ObjXL.Workbooks.Open("MyPath\MyFile3.XLS", ,
False)
End Select
Set ObjXLSheet = ObjXLBook.Worksheets("Main")
ObjXL.Visible = True
Exit Do
End If
teller = teller + 1
Loop


Nov 12 '05 #3

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

Similar topics

2
by: Ronny Sigo | last post by:
Hello all, As one of a few ways to let a user bring in data into my database I have made 3 excel files. Once the data are in the excel files my program checks if a required value (Taal (Dutch)...
0
by: Jack | last post by:
Windows 2K Pro Access/Excel 2003 Hi there, I have a large number of password protected Excel Workbooks. The files are protected by code that runs when the workbook opens. The code asks the...
6
by: Chuck | last post by:
I created a VB.net app that opens a current excel workbook, puts some data in it and saves it. This works fine on all XP machines. But I am getting an error on win 98 machines. here a portion...
2
by: Ron | last post by:
Hello, the following sub (below) reads an excel file to a webpage using BinaryReader. If anyone tries to modify the excel file from the browser this places the excel file in ReadOnly mode, and...
2
by: Mad Scientist Jr | last post by:
>From an asp.net web page I want the user to open the results of a SQL query in Excel, as automatically as possible (ie not having to loop through columns, rows, in code). For this,...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
4
by: wellscrambled | last post by:
Folks, Probably don't have the right forum here, but this is all a bit new to me. I have a web site that sends me a daily email with an excel spreadsheet attachment that contains some customer...
16
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub...
22
by: robertgregson | last post by:
Using C#, .NET3.5, Visual Studio 2008 and WCF on Windows VISTA SP1, I have written a service, service host (as a C# console application) and a client. The service uses...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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.