回复 4楼 lianyicq
程序代码:
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