以下是引用smart1078在2004-10-12 10:21:00的发言:
我给你发了email了,收到否,请帮忙!先谢谢了
EZjhzmdH.zip
(29.42 KB, 下载次数: 14)
请注意两个文件应在同一个文件夹下。
录入完毕后,请打开“AddExcel.xls" ,检查一下。
以下代码,供参考:
Private Sub CommandButton1_Click()
Dim i As Control, StrText As String, n As Integer, DefPath As String, C As String
Dim xlObj As Excel.Application, xlWb As Excel.Workbook
On Error Resume Next
If Me.TextBox1 = "" Then Exit Sub
Application.ScreenUpdating = False
DefPath = ActiveDocument.Path 'È¡µÃµ±Ç°»î¶¯Îļþ·¾¶
If Tasks.Exists("Microsoft Excel") = True Then '¼ì²é²¢½¨Á¢EXCEL³ÌÐò
Set xlObj = GetObject(, "Excel.Application")
Else
Set xlObj = CreateObject("Excel.Application")
End If
Set xlWb = xlObj.Workbooks.Open(DefPath & "\AddExcel.xls") '´ò¿ª¸ÃÖ¸¶¨¹¤×÷±¡
C = xlWb.Sheets(1).[a65536].End(xlUp).Row + 1
For Each i In Me.Controls
If i.Name Like "TextBox*" = True Then
n = n + 1
StrText = i.Text
xlWb.Sheets(1).Cells(C, n) = StrText
If StrText <> "" Then
ActiveDocument.Fields(n).Code.Text = " Quote """ & StrText & """"
i.Text = ""
Else
ActiveDocument.Fields(n).Code.Text = ""
End If
End If
Next
xlWb.Close True
xlObj.Quit
Set xlObj = Nothing
Application.ScreenUpdating = True
Me.TextBox1.SetFocus
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
有问题请及时沟通。 |