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

How to reference individual cells in Excel via VBA

Hello all,
Could anybody help me referencing individual cells in excel? I don't know
what I do wrong here (but I'm not familiar with excel vba) (Microsoft Excel
10.0 Object library is referenced)
Any help very much appreciated
Thanks
Ronny

Private Sub btnTargetAffGroupEmailImport_Click()
Dim MyXL As Object
Dim ExcelWasNotRunning As Boolean
On Error Resume Next ' Defer error trapping.
Set MyXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True
Err.Clear
DetectExcel ' I HAVE PASTED THIS FUNCTION BELOW .....
Set MyXL = GetObject("U:\MIJNTEST.XLS")
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
'HERE I HAVE TO REFERENCE THE INDIVIDUAL CELLS
MyXL.cell(2, 2) = "Een"
MyXL.cell(2, 3) = "Twee"
MyXL.cell(2, 4) = "Drie"
MyXL.cell(2, 5) = "Vier"

If ExcelWasNotRunning = True Then
MyXL.Application.Quit
End If

Set MyXL = Nothing ' Release reference to the
' application and spreadsheet.

End Sub
Public Function DetectExcel()
' Procedure dectects a running Excel and registers it.
Const WM_USER = 1024
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow("XLMAIN", 0)
If hWnd = 0 Then ' 0 means Excel not running.
Exit Function
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Function
Nov 12 '05 #1
2 3279
From my file:

See below my SIG
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com

Refer To A Specific Cell In An Excel Worksheet

ObjWkb.Worksheets(1).Cells(Row, Col).Value

Row = Integer, specifying the row number

Col = Integer, specifying the column number
"Ronny Sigo" <ro********@skynet.be> wrote in message
news:40***********************@feed0.news.be.easyn et.net...
Hello all,
Could anybody help me referencing individual cells in excel? I don't know
what I do wrong here (but I'm not familiar with excel vba) (Microsoft Excel
10.0 Object library is referenced)
Any help very much appreciated
Thanks
Ronny

Private Sub btnTargetAffGroupEmailImport_Click()
Dim MyXL As Object
Dim ExcelWasNotRunning As Boolean
On Error Resume Next ' Defer error trapping.
Set MyXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True
Err.Clear
DetectExcel ' I HAVE PASTED THIS FUNCTION BELOW .....
Set MyXL = GetObject("U:\MIJNTEST.XLS")
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
'HERE I HAVE TO REFERENCE THE INDIVIDUAL CELLS
MyXL.cell(2, 2) = "Een"
MyXL.cell(2, 3) = "Twee"
MyXL.cell(2, 4) = "Drie"
MyXL.cell(2, 5) = "Vier"

If ExcelWasNotRunning = True Then
MyXL.Application.Quit
End If

Set MyXL = Nothing ' Release reference to the
' application and spreadsheet.

End Sub
Public Function DetectExcel()
' Procedure dectects a running Excel and registers it.
Const WM_USER = 1024
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow("XLMAIN", 0)
If hWnd = 0 Then ' 0 means Excel not running.
Exit Function
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Function

Nov 12 '05 #2
Works great! Thank you!

"PC Datasheet" <sp**@nospam.spam> schreef in bericht
news:p8******************@newsread3.news.atl.earth link.net...
From my file:

See below my SIG
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com

Refer To A Specific Cell In An Excel Worksheet

ObjWkb.Worksheets(1).Cells(Row, Col).Value

Row = Integer, specifying the row number

Col = Integer, specifying the column number
"Ronny Sigo" <ro********@skynet.be> wrote in message
news:40***********************@feed0.news.be.easyn et.net...
Hello all,
Could anybody help me referencing individual cells in excel? I don't know what I do wrong here (but I'm not familiar with excel vba) (Microsoft Excel 10.0 Object library is referenced)
Any help very much appreciated
Thanks
Ronny

Private Sub btnTargetAffGroupEmailImport_Click()
Dim MyXL As Object
Dim ExcelWasNotRunning As Boolean
On Error Resume Next ' Defer error trapping.
Set MyXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True
Err.Clear
DetectExcel ' I HAVE PASTED THIS FUNCTION BELOW .....
Set MyXL = GetObject("U:\MIJNTEST.XLS")
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
'HERE I HAVE TO REFERENCE THE INDIVIDUAL CELLS
MyXL.cell(2, 2) = "Een"
MyXL.cell(2, 3) = "Twee"
MyXL.cell(2, 4) = "Drie"
MyXL.cell(2, 5) = "Vier"

If ExcelWasNotRunning = True Then
MyXL.Application.Quit
End If

Set MyXL = Nothing ' Release reference to the
' application and spreadsheet.

End Sub
Public Function DetectExcel()
' Procedure dectects a running Excel and registers it.
Const WM_USER = 1024
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow("XLMAIN", 0)
If hWnd = 0 Then ' 0 means Excel not running.
Exit Function
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Function


Nov 12 '05 #3

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

Similar topics

3
by: zxo102 | last post by:
Hi there, I need your help for python <--> excel. I want to paste selected cells (range) to different location on the same sheet in Excel through python. I have tried it for a while but could not...
2
by: Ronny Sigo | last post by:
Hello all, Could anybody help me referencing individual cells in excel? I don't know what I do wrong here (but I'm not familiar with excel vba) (Microsoft Excel 10.0 Object library is referenced)...
3
by: Damian Arntzen | last post by:
I'm a beginner to moderate programmer who's fiddling around with automating Excel, in particular after being able to have the user fill out a form and it then generate the workbook. I can't quite...
2
by: Chris Bellini | last post by:
Greetings! I'm developing a C# application that needs to read some data from a selected XLS file. I've used VB in the past to automate Excel but this is the first time I've used C#. Back in VB,...
4
by: Lee | last post by:
I am having a heck of a time trying to learn how to manipulate Excel from Visual Basic.NET. Does anyone know of any good reference articles or books that address this subject specifically? I...
1
by: Glen Vermeylen | last post by:
Hi, For a project at school we have to automate the assignment of seats in classrooms to students during the exams. The lady who previously did everything manually kept the layouts of the...
5
by: mrid via DotNetMonster.com | last post by:
hi. im exporting data from a vb form to excel. i am able to create a new excel file, save and edit it without any trouble, but the formatting is giving me hell! i need to be able to show certain...
1
by: thadson | last post by:
Hi, I'm trying to import specific cells from MS Excel 2000 spreadsheets to MS Access 2000 tables then move the spreadsheets to a different directory. I'm very new to this and I'm having trouble...
4
by: ielamrani | last post by:
Hi, I am getting this error when I try to export to an excel sheet. When I click on a button to export the first time it's fine, I rename the exported excel sheet and I try to export it again and I...
1
by: randyse | last post by:
Hello all, This is my first post, please let me know if I've missed any relevant data or guidelines. I'm using Access 2003 for the database and Excel 2003 for the reporting to avoid having...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.