Home > Software engineering >  VB data saved to the EXCEL table regularly how can not cover
VB data saved to the EXCEL table regularly how can not cover

Time:10-21

The following code
 Private Sub Timer2_Timer () 
Dim ExcelApp As Object, ExcelBook As Object, Q As Integer

The Set ExcelApp=CreateObject (" Excel. Application ")
The Set ExcelBook=ExcelApp. Workbooks. Open (" D: \ Book2. XLS ") 'file name it ourselves, the file must exist
With ExcelBook. ActiveSheet

Q=. UsedRange. Rows. Count + 1
The Static R
R=Q + 1
The Range (" A "& amp; R & amp; : "K" & amp; R)=Array (the Format (Now, "yy/mm/dd, hh: mm: ss"), text1 (0). The Text, text1. (1) Text, text1. (2) Text, text1. (3) Text, text1. (4) Text, text1. (5) Text, text1 (6). The Text, text1 (7). The Text, text1 (8), Text, text1 (9). The Text, text1 (10). The Text)
End With
ExcelBook. Save
ExcelBook. Close
ExcelApp. Quit

End Sub

This code runs successfully inside every once in a while to EXCEL automatically write data and one line to write, but I manually remove the EXCEL table of contents, at the time of running the program, started to cover on a record, seek the solution, xiaodi bucai, hope get unexpected help

CodePudding user response:

Should better understand the UsedRange properties after emptying the contents, UsedRange properties will change, so it's possible to cover the previous position, if can't cover, can consider to use a specific range of end attribute or variable storage or cell line number...

CodePudding user response:

There is no doubt that you are wrong to use excel to record keeping data was wrong.
At the very least, you should also use access, at least it is a database.

CodePudding user response:

Excel can be used as a Jet Engine to use external database, using ADO and SQL can keep writing new records,
  • Related