‘要先单击“工程-部件”,显示“部件”对话框,将“Microsoft Common Dialog control 6.0(SP6)”选中,在工具栏就多出了一个CommonDialog控件图标,将其添加到窗体上 Private Sub Command1_Click() CommonDialog1.CancelError = True CommonDialog1.DialogTitle = "选定要打开的Excel文件" CommonDialog1.InitDir = App.Path CommonDialog1.Filter = "Xls文件(*.Xls)|*.Xls|所有文件(*.*)|*.*" CommonDialog1.InitDir = App.Path CommonDialog1.ShowOpen If Err <> cdlCancel Then TxtFileName = CommonDialog1.FileName Else Exit Sub End If Set xlApp = CreateObject("Excel.Application") ‘创建EXCEL对象 xlApp.Visible = True Set xlBook = xlApp.Workbooks.Open(TxtFileName) End Sub 注意最后要关闭 On Error Resume Next xlBook.Save xlBook.Close (True) ‘关闭工作簿............................................. xlApp.Quit ‘结束EXCEL对象.................................................... Set xlApp = Nothing ‘释放xlApp对象.............................................!!!
时间: 2024-12-28 13:16:29