473,396 Members | 2,061 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,396 software developers and data experts.

Can't acces the right excel sheet with vba

Hello all,
I am trying to automate Excel via vba(access). If I try to write values in
the second sheet (InkNieuweleden)of the workbook the program puts these
values always in the first sheet (InkBijbetalers). Can anybody tell me what
I'm doing wrong here?
Here follows a snippet of the code:

Private Sub Command44_Click()
DoCmd.Hourglass True
Dim ObjXL As Excel.Application
Dim ObjXLBook As Excel.Workbook
Dim ObjXLSheet As Excel.Worksheet
If fIsAppRunning("Excel") Then
Set ObjXL = GetObject(, "Excel.Application")
'boolXL = False
Else
Set ObjXL = CreateObject("Excel.Application")
'boolXL = True
End If
Set ObjXLBook = ObjXL.Workbooks.Open("MyPath\Boekhouding_WorkCopy. xls", ,
False)
Set ObjXLSheet = ObjXLBook.Worksheets("InkNieuweleden")
ObjXL.Cells(1, 1).Value = "Bestand aangemaakt op: " & Date

Aantalkols = 193
Rij = 5
Kol = 1
teller = 1

Do While Rij < 25
teller = 1
Do While teller < 6
Do While Kol < Aantalkols + 1
ObjXL.Cells(Rij, Kol).Value = "this is an emptystring - will
change that later with.select"
Kol = Kol + 6
Loop
Aantalkols = Aantalkols + 1
teller = teller + 1
Kol = teller
Loop
Rij = Rij + 1
Kol = 1
Aantalkols = 193
Loop
Dim dbs1 As DAO.Database
Dim rst1 As DAO.Recordset
Dim strSQL1 As String

strSQL1 = "SELECT * FROM Leden where [Betaald] = 10 and [Oudgediende] =
False order by [Achternaam]"
Set dbs1 = CurrentDb
Set rst1 = dbs1.OpenRecordset(strSQL1)
If rst1.RecordCount <> 0 Then
rst1.MoveFirst
Rij = 5
Kol = 1
Aantalkols = 193

Do While Not rst1.EOF And Kol < Aantalkols + 1
ObjXL.Cells(Rij, Kol).Value = rst!DatumBetaling
ObjXL.Cells(Rij, Kol + 1).Value = rst!Betaald - Eerstbetaald
ObjXL.Cells(Rij, Kol + 2).Value = rst!ID
ObjXL.Cells(Rij, Kol + 3).Value = rst!Achternaam
ObjXL.Cells(Rij, Kol + 4).Value = rst!Voornaam
Rij = Rij + 1
If Rij = 25 Then
Rij = 5
Kol = Kol + 6
End If
rst1.MoveNext
Loop

If Not rst1 Is Nothing Then
rst1.Close
Set rst1 = Nothing
End If

If Not dbs1 Is Nothing Then
Set dbs1 = Nothing
End If
End If
ObjXLBook.Save
DoCmd.Hourglass False
ObjXL.Visible = True
End Sub
Nov 13 '05 #1
2 2369
"Ronny Sigo" <roon ad skynet.be> wrote in message news:<40***********************@news.skynet.be>...
Hello all,
I am trying to automate Excel via vba(access). If I try to write values in
the second sheet (InkNieuweleden)of the workbook the program puts these
values always in the first sheet (InkBijbetalers). Can anybody tell me what
I'm doing wrong here?
Here follows a snippet of the code:
...


Ronny,

Simply setting ObjXLSheet to the second sheet doesn't make other
references use the second sheet. You never even referenced ObjXLSheet
after you set it. If you want to reference the second sheet you must
use your ObjXLSheet:

With ObjXLSheet
.Cells(3, "C").Value = 5
End With

or possibly even (sloppy way):

Sheets("InkNieuweleden").Select
ActiveSheet.Cells(3, "C").Value = 5

James A. Fortune
Nov 13 '05 #2
"Ronny Sigo" <roon ad skynet.be> wrote in message news:<40***********************@news.skynet.be>...
Hello all,
I am trying to automate Excel via vba(access). If I try to write values in
the second sheet (InkNieuweleden)of the workbook the program puts these
values always in the first sheet (InkBijbetalers). Can anybody tell me what
I'm doing wrong here?
Here follows a snippet of the code:
...


Ronny,

Simply setting ObjXLSheet to the second sheet doesn't make other
references use the second sheet. You never even referenced ObjXLSheet
after you set it. If you want to reference the second sheet you must
use your ObjXLSheet:

With ObjXLSheet
.Cells(3, "C").Value = 5
End With

or possibly even (sloppy way):

Sheets("InkNieuweleden").Select
ActiveSheet.Cells(3, "C").Value = 5

James A. Fortune
Nov 13 '05 #3

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

Similar topics

5
by: Rajiv | last post by:
HI ALL, actually , i m working in a company having large number of employee , i have two userid and password . on id is from admin group(id given to me by technology manager) of the server and...
0
by: I Decker | last post by:
Hi all, Hope this is the right group. I am writing a program in c# to open create an excel document, enter some data, save it and then email it as an attachment. I have successfully created...
1
by: Vivek | last post by:
Hi all, I am trying to import data from an excel sheet to MSSQL server 2000 using a web application (C#). Since I have to validate the data in the excel sheet, the approach i have used is to get...
3
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel...
18
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a...
3
by: rlntemp-gng | last post by:
RE: Access 2003/Excel 2003 Problem: After I close the Access application completely, I go out to the Task Manager and there is an Excel.exe object still sitting out there. My Access...
0
by: rajeshkothuru | last post by:
Hi I am new to perl programming, i stcked at one line. I have written code such that new excel sheet will save accordingly even though if already existed Excel sheet persists. The problem is if...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
2
by: ravir81 | last post by:
Hi, I am working on excel reporting using Perl. I am facing problem with writing the header part only once for all the excels created using Perl. Here is the code : ...
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?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.