Click to See Complete Forum and Search --> : Updating an excel document
WeeBeng
March 18th, 2001, 09:28 AM
I have this programme which adds information to an Excel document in a few columns and rows. I would like to have the ability to add in
new information to the same document after I have exit and then reentered the programme a new time. How can I know which row to continue adding
my new information after I have exit?
Is there a easy way to do this ?
Iouri
March 18th, 2001, 11:05 AM
THis code will help upo to find last/first filled col/row
Dim excel_app As Object
Dim excel_sheet As Object
Dim new_value As String
Dim first_row As Integer
Dim first_col As Integer
Dim num_rows As Integer
Dim num_cols As Integer
' Create the Excel application.
Set excel_app = CreateObject("Excel.Application")
' Uncomment this line to make Excel visible.
' excel_app.Visible = True
' Open the Excel spreadsheet.
excel_app.Workbooks.Open FileName:=txtExcelFile.Text
' Check for later versions.
If Val(excel_app.Application.Version) >= 8 Then
Set excel_sheet = excel_app.ActiveSheet
Else
Set excel_sheet = excel_app
End If
' Get and display the bounds.
first_row = excel_sheet.UsedRange.Row
first_col = excel_sheet.UsedRange.Column
num_rows = excel_sheet.UsedRange.Rows.Count
num_cols = excel_sheet.UsedRange.Columns.Count
MsgBox "Rows: " & Format$(first_row) & _
" - " & Format$(first_row + num_rows - 1) & vbCrLf & _
"Cols: " & Format$(first_col) & _
" - " & Format$(first_col + num_cols - 1)
' Comment the rest of the lines to keep
' Excel running so you can see it.
' Close the workbook without saving.
excel_app.ActiveWorkbook.Close False
' Close Excel.
excel_app.Quit
Set excel_sheet = Nothing
Set excel_app = Nothing
Iouri Boutchkine
iouri@hotsheet.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.