| |

VerySource

 Forgot password?
 Register
Search
View: 863|Reply: 3

How to read data in excel in vb?

[Copy link]

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-27 11:00:01
| Show all posts |Read mode
I am a newbie and want to try to make a program, import the data from excel into the vb program table and select and print. Please help me! !!
Reply

Use magic Report

0

Threads

16

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-2-23 12:00:02
| Show all posts
I imported the data from excel into the MSHFlexGrid1.TextMatrix (i, 1) control! For the reference of the landlord

Private Sub MnuInput_Click ()
Rem saves the data in the table
Dim FileName As String '' '' '' '' '' 'Save data to Excel table
Dim i As Integer
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Excel table | * .xls"
CommonDialog1.ShowOpen
FileName = CommonDialog1.FileName
If FileName = "" Then
  Exit Sub
End If
 
Set xlApp = CreateObject ("Excel.Application")
`` Set xlBook = xlApp.Workbooks '' .Add ''
Set xlBook = xlApp.Workbooks.Open (FileName)
‘’ ’Set xlBook = xlApp.Workbooks.Open (" c:\lizi.xls ")‘ ’’

Set xlSheet = xlBook.Worksheets (1) '' '' '' Open Excel sheet
xlSheet.Activate '' activate sheet

For i = 0 To 27
'' For Alfi = 0 To 90 Step 18

 MSHFlexGrid1.TextMatrix (i, 1) = xlSheet.Cells (i + 1, 1) '' '' 'Import MSFlexGrid data into Excel

 MSHFlexGrid1.TextMatrix (i, 2) = xlSheet.Cells (i + 1, 2)

'' Next Alfi
Next i
'' 'xlBook.SaveAs FileName
xlBook.RunAutoMacros (xlAutoClose) '' 'Execute Excel close macro
xlBook.Close (True) '' '' 'Close Excel worksheet
xlApp.Quit '' '' '' '' 'Close Excel Workbook
Set xlApp = Nothing
End Sub
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-2 08:00:01
| Show all posts
Have a positive solution
Reply

Use magic Report

0

Threads

21

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-3-3 15:00:01
| Show all posts
Upstairs can basically solve the problem of the landlord!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list