Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing variables to an Excel spreadsheet 2

Status
Not open for further replies.

Stuartp

Technical User
Feb 22, 2001
178
GB
I have several variables in my program and I wish to write their values in a single line on an Excel 2000 spreadsheet that I have on my hard drive. They will always be written to the same cells in the same worksheet, so I need to have the program delete the existing contents and enter the new ones so I can then draw a graph of these variable values.

Can someone please help me to do this?

Many thanks

Stuart
 
Hi my friend
1- Set a refrence to Excel in your project

2- In the General Declarations of your form
Dim xl As Excel.Application
Option Explicit
3-
Private Sub Command1_Click()
' Use your variables instead of MyVar1,2
Dim MyVar1 As String
Dim MyVar2 As String
MyVar1 = "Hello"
MyVar2 = "World"
Set xl = New Excel.Application
With xl

.Visible = False
.Workbooks.Open ("D:\book4")
.Range("A1").Value = MyVar1
.Range("B1").Value = MyVar2
.ActiveWorkbook.Close SaveChanges:=True
.Quit
End With
Set xl = Nothing

End Sub
4- Don't worry about deleting the last values, the new ones will overwrite them.
Hope this will help
Walid Magd
Engwam@Hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top