


Use VB to write data in the control to Excel row by row and column by column
Use VB to write the data in the control to Excel row by row and column by column
Please quote excel,
dim xls as new excel.application
dim wb as excel.workbook
dim sht as excle.worksheet
'The above is the form variable
'form load
set wb =xls.workboods.add("F:\data.xls")
set sht =wb.worksheets(1)
'---' button:
dim r as integer
r=sht.range("A65536").end(xlsup).row 1
sht(r,1)=text1.text
sht(r,2)=text2.text
wb.save
'---when form unload
wb.close
xls.quit
Option Explicit
Dim xls As Excel.Application Dim wb As Excel.Workbook Dim sht As Excel.Worksheet
Private Sub Command1_Click() TryOpenXls Dim r As Integer r = sht.Range("A65536").End(xlUp).Row 1 If r = 2 And sht.Range("A1").Value = """ And sht.Range("B1").Value = "" Then r = 1 sht.Cells(r, 1) = Text1.Text sht.Cells(r, 2) = Text2.Text wb.Save End Sub
Private Sub TryOpenXls() On Error Resume Next Dim x As String Dim path As String path = App.path & "\abc.xls" Err.Clear x = xls.Name If Err.Number 0 Then Set xls = New Excel.Application End If x = wb.Name If Err.Number 0 Then On Error GoTo 0 If Len(Dir(path)) = 0 Then Set wb = xls.Workbooks.Add wb.SaveAs path Else Set wb = xls.Workbooks.Open(path) End If End If
On Error GoTo 0 Set sht = wb.Worksheets(1) End Sub
Private Sub Form_Unload(Cancel As Integer) On Error Resume Next Set sht = Nothing If Not wb Is Nothing Then wb.Save: wb.Close If Not xls Is Nothing Then xls.Quit Set wb = Nothing Set xls = Nothing End Sub
How to import the data calculated in vb into excel
I didn’t read your program
Give you some reference
Leave a message if you have any questions
set e = CreateObject("Excel.Application")
e.visible = 0
set nb = e.workbooks.add
set ns = nb.worksheets(1)
for i = 1 to 10
for j = 1 to 10
ns.cells(i,j) = cstr(i) & "," & cstr(j)
next
next
ns.saveas "c:\a.xlsx"
e.quit
set e = CreateObject("Excel.Application")
e.visible = 0
set nb = e.workbooks.add
set ns = nb.worksheets(1)
for i = 1 to 10
for j = 97 to 105
k = chr(j)
ns.range(k&i).value = "The"&i&"th"
next:next
ns.saveas "c:\a.xls"
e.quit
VB saves array data to Excel
Private Sub Command1_Click()
Dim XlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
XlApp.Visible = True
Set xlBook = XlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
For i=1 to 20 'Your array has 21 numbers, not 20 numbers
xlSheet.Range(xlSheet.Cells(1,i).Value=a1(i)
xlSheet.Range(xlSheet.Cells(2,i).Value=b1(i)
xlSheet.Range(xlSheet.Cells(3,i).Value=c1(i)
xlSheet.Range(xlSheet.Cells(4,i).Value=d1(i)
xlSheet.Range(xlSheet.Cells(5,i).Value=e1(i)
xlSheet.Range(xlSheet.Cells(6,i).Value=f1(i)
Next i
End Sub
The above is the detailed content of Use VB to write data in the control to Excel row by row and column by column. For more information, please follow other related articles on the PHP Chinese website!

You may encounter the “this build of Vanguard is out of compliance” issue when attempting to launch Valorant on Windows 11. Why does the error message appear? How to get rid of the error message? This post from php.cn gives details.

NVIDIA GeForce RTX 40 series GPU might not be a new thing to you. Compared with other top graphics cards, many of you may pay more attention to mid-end mainstream RTX 4050 for its acceptable price. Read through this guide from php.cn Website to get d

KB2267602 is a protection or definition update for Windows Defender designed to fix vulnerabilities and threats in Windows. Some users reported that they were unable to install KB2267602. This post from php.cn introduces how to fix the “KB2267602 fai

Do you know how to reinstall pre-installed software in Windows 11 if you need to do this? In this post, we will introduce two easy ways. In addition, if you want to recover files on your Windows computer, you can try php.cn Power Data Recovery.

Windows Desktop or File Explorer or folder will automatically refresh itself when you make some changes to it. However, some Windows 11/10 users report that they encounter the “desktop and file folders do not refresh automatically” issue. This post f

When you try to install a program on Windows 11/10, you may fail to install it and receive an error message - there is a problem with this Windows installer package. This post from php.cn helps you to fix it.

When you run antivirus software on your device, you likely expect it to scan all files and folders for viruses. However, one question arises: can antivirus scan encrypted files? This inquiry delves into the realm of security versus privacy. php.cn So

How to download HDMI video drivers on Windows? How to update HDMI drivers to the latest versions. You can find the ways here. In addition, you can try php.cn Power Data Recovery to get your lost and deleted files back if necessary.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool