用OLE显示Excel问题
请教一下,我想在打开的Excel工作簿中根据条件查询,然后将结果所在的这几行显示在OLE中,工作簿中有好几个表。有办法实现吗?另外,求一份VB操作Excel的详细资料,谁有的话能不能发我一份呀?我邮箱894521642@,先谢啦~
2015-07-22 19:33

2015-07-23 09:18

2015-07-23 09:54

2015-07-23 10:00
程序代码:Option Explicit
Public xlApp As New Excel.Application
Public xlBook As Excel.Workbook
Public xlSheet As Excel.Worksheet
Dim oBook As Object
Dim oSheet As Object
Dim myfilename As String
Private Sub Command1_Click()
Dim dest As String
Dim i As Integer
Dim x As Integer
Dim y As Integer
Dim p As Excel.Range
Dim firstaddress
On Error GoTo Err_Handler
OLE1.CreateEmbed vbNullString, "Excel.Sheet"
Set oBook = OLE1.object
Set oSheet = oBook.Sheets(1)
dest = Text1.Text
For i = 1 To xlBook.Worksheets.Count
With xlSheet
y = 1
Do While .Cells(1, y).Value <> "" '以首行有数据为列有数据的判断
x = 1
Do While .Cells(x, 1) <> "" '列内判断
If "dest" Like "*" & .Cells(x, y).Value & "*" Then
.Rows(x).Copy
'Set xlBook = xlApp.Workbooks.Open(myfilename)
oSheet.Paste Destination:=.Rows(x)
Exit Do
End If
x = x + 1
Loop
y = y + 1
Loop
End With
Next
oBook.Application.Selection.AutoFormat
Exit Sub
'xlBook.Close
'Set xlSheet = Nothing
'Set xlBook = Nothing
'Set xlApp = Nothing
Err_Handler:
MsgBox "The file myfilename does not exist" & _
" or cannot be opened.", vbCritical
End Sub
2015-07-23 17:31
2015-07-23 17:34
2015-07-24 10:26