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

Visual Basic 6.0 and Excel

JW
I am looking for sample code to learn me about using excel from a visual
basic program.

I want to open a file, store code in a certain cell and save this again.

Who can help me

Regards
Jul 17 '05 #1
3 26221

"JW" <j@hetnet.nl> wrote in message news:c1**********@reader08.wxs.nl...
I am looking for sample code to learn me about using excel from a visual basic program.

I want to open a file, store code in a certain cell and save this again.
Who can help me

Regards


This example shows the basic operations.
Set a reference in you VB project to the Microsoft Excel Object Library.

Private Sub Command1_Click()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet

Set oXL = New Excel.Application
Set oWB = oXL.Workbooks.Open("C:\Documents\MyFile.xls")
Set oWS = oWB.Worksheets("Sheet1")

oWS.Range("B1").Value = 23.5
oWS.Range("B2").Value = 17.6
oWS.Range("B3").Formula = "=B1+B2"

oWB.Save

oXL.Quit

End Sub


Jul 17 '05 #2
Hi

I have p[icked up this thread and have a student who is trying to enter data
to Excel from a VB form and this works a treat. Is there any way to get the
system to enter each instance into successive rows in the spreadsheet.

e.g. first use enters to B1,C1,D1 and the next to B2,C2,D2 etc. etc.

Regards

Terry

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:Ib********************@comcast.com...

"JW" <j@hetnet.nl> wrote in message news:c1**********@reader08.wxs.nl...
I am looking for sample code to learn me about using excel from a

visual
basic program.

I want to open a file, store code in a certain cell and save this

again.

Who can help me

Regards


This example shows the basic operations.
Set a reference in you VB project to the Microsoft Excel Object Library.

Private Sub Command1_Click()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet

Set oXL = New Excel.Application
Set oWB = oXL.Workbooks.Open("C:\Documents\MyFile.xls")
Set oWS = oWB.Worksheets("Sheet1")

oWS.Range("B1").Value = 23.5
oWS.Range("B2").Value = 17.6
oWS.Range("B3").Formula = "=B1+B2"

oWB.Save

oXL.Quit

End Sub

Jul 17 '05 #3
In the previous example, you could use

oWS.Cells(mRow, 2).Value = 23.5
oWS.Cells(mRow, 3).Value = 17.6
oWS.Cells(mRow, 4).Value = 19

where mRow is a variable in the module, and the 2, 3, and 4 are column
numbers (i.e. B, C, and D).

So, you could start with mRow = 1, then increment it each time the
procedure is called.

"terry.wright" <te***@wrico.karoo.co.uk> wrote in message
news:Rt********************@karoo.co.uk...
Hi

I have p[icked up this thread and have a student who is trying to enter data to Excel from a VB form and this works a treat. Is there any way to get the system to enter each instance into successive rows in the spreadsheet.

e.g. first use enters to B1,C1,D1 and the next to B2,C2,D2 etc. etc.

Regards

Terry

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:Ib********************@comcast.com...

"JW" <j@hetnet.nl> wrote in message news:c1**********@reader08.wxs.nl...
I am looking for sample code to learn me about using excel from a

visual
basic program.

I want to open a file, store code in a certain cell and save this

again.

Who can help me

Regards


This example shows the basic operations.
Set a reference in you VB project to the Microsoft Excel Object Library.
Private Sub Command1_Click()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet

Set oXL = New Excel.Application
Set oWB = oXL.Workbooks.Open("C:\Documents\MyFile.xls")
Set oWS = oWB.Worksheets("Sheet1")

oWS.Range("B1").Value = 23.5
oWS.Range("B2").Value = 17.6
oWS.Range("B3").Formula = "=B1+B2"

oWB.Save

oXL.Quit

End Sub


Jul 17 '05 #4

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

Similar topics

3
by: Omar | last post by:
Hi Developers, I am trying to access an Excel data file through a VB.Net application. I have the following code: =================================== VB.Net Code =================== Dim...
2
by: Rebecca | last post by:
could someone tell me the correct syntax for using vlookup in visual basic
5
by: JimS | last post by:
I just got myself a Visual Basic.Net compiler, and I'm looking for books to help me learn. Specifically, I'm a very experienced programmer (going back to 1968), I'm pretty accomplished in VBA for...
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
1
by: akshaysk | last post by:
HI, I am new to Visual Basic. For my Assignment i am supposed to write a visual basic program using excel. I have tried many scripts, but receive errors. Can anyone tell me of any website that...
4
by: bilalbajwa2336 | last post by:
I want to make a program in visual basic. When i put my salary data in VB (like: Time In , Time Out, DAte, DAy) VB automatically (in the back ground) input this data in the Excel and Show out puts of...
2
by: Vmrincon | last post by:
Hi! I need to crete a visual basic .net application to read Excel 2000 files. Does anyone know if I need some kind of driver or some extra file to be able to do it? Thanks a lot!
1
by: chrspta | last post by:
I am new to Visual basic. I need a program using VB6 that converts txt files to excel file.Description is in the below: The form should have the Drive list, Dir list, file list and cmdConvert...
4
by: bonkbc | last post by:
hi! how can we take textbox data from a visual basic 6.0 form and write it to an excel worksheet once a command button is clicked? I've gotten very close to completing this on my own, here is...
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: 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...
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
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...

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.