guotianxin 版主的输出EXCEL并运行EXCEL中的宏的代码如下:
Option Compare Database
Private Sub Command0_Click()
Dim sFile As String
On Error Resume Next
GetExcel
MyXl.Application.Workbooks.Open Filename:="C:\Test\Member.xls"
MyXl.Application.Run "Macro1"
End Sub
另还有个模块如下:
Option Compare Database
Public MyXl As Object
'打开 Excel
Sub GetExcel()
Const ERR_APP_NOTRUNNING As Long = 429
On Error Resume Next
Set MyXl = GetObject(, "Excel.Application")
If Err = ERR_APP_NOTRUNNING Then
Set MyXl = New Excel.Application
End If
MyXl.Application.Visible = True
End Sub
我照实例做的一个字窗体输出EXCEL的代码如下:
Private Sub 子窗_Click()
1001 CurrentDb.Execute "delete * from 临时"
1002 Me![个性材料数量登记子窗体].SetFocus
1003 DoCmd.RunCommand acCmdSelectAllRecords '选取所有记录
1004 DoCmd.RunCommand acCmdCopy '¸´复制
1005 DoCmd.OpenTable "临时" '开启数据表
1006 DoCmd.SetWarnings False
1007 DoCmd.RunCommand acCmdPasteAppend '贴上新增
1009 DoCmd.SetWarnings True
1010 DoCmd.Close '关闭数据表
1011 DoCmd.TransferSpreadsheet acExport, 8, "临时, _
CurrentProject.Path & "\" & "临时表.xls", True, "" '汇出"
1012 Set b = CreateObject("excel.application")
1013 b.Visible = True
1014 b.workbooks.Open CurrentProject.Path & "\" & "临时表.xls"
End Sub
我用的代码输出后,运行EXCEL中的宏Macro1,但不知怎样把guotianxin 版主加到我的代码中去?
另,输出WORD后,运行WORD中的宏,是怎样做呢?
[此贴子已经被作者于2004-11-24 9:36:23编辑过]
|