473,388 Members | 1,340 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,388 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 26220

"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: 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: 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: 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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.