我正在使用此功能将工作簿中的工作表复制到另一个工作簿。我工作,但似乎如果我禁用工作簿中的宏,它就不能再复制工作表了。
如果我改变这条线: m_objExcel.AutomationSecurity = msoAutomationSecurityForceDisable
对此 m_objExcel.AutomationSecurity = msoAutomationSecurityByUI
它可以工作,但会收到警告消息。此外,如果我评论该行,它可以完美运行,但使用宏。
Private Sub CopyFunction()
Set m_objExcel = New Excel.Application 'creare obiect
m_objExcel.DisplayAlerts = False
g_secAutomation = m_objExcel.AutomationSecurity
m_objExcel.AutomationSecurity = msoAutomationSecurityForceDisable
m_objExcel.Visible = True
Dim CopyFrom As Workbook
Dim CopyTo As Workbook
Dim CopyThis As Object
Set CopyFrom = m_objExcel.Workbooks.Open("D:\FromFile.xls")
Set CopyTo = m_objExcel.Workbooks.Open("D:\ToFile.xls")
Set CopyThis = CopyFrom.Sheets(1) ''Sheet number 1
CopyThis.Copy After:=CopyTo.Sheets(1)
m_objExcel.Workbooks(CopyTo.FullName).Save
CopyFrom.Close
CopyTo.Close
m_objExcel.Workbooks.Close
MsgBox "ok"
End Sub
我在 Access 中使用它并使用 Excel 文件。问题是什么?有没有办法仍然能够将工作簿中的工作表复制到另一个工作簿并禁用宏?