如何在Excel中使用文件对话框
时间:2013-07-02 08:17 来源:网络 作者:未知 阅读:次
如何在Excel中使用文件对话框 注意,打开程序的时候点击:工程-引用-“microsoft excel 11.0 object library”(我的是XP版本和OFFICE2003) + 工程-部件-"microsoft common dialog control 6.0" '定义excel对象 Public oldxls As Excel.Application '定义工作簿对象 Public oldbook As Excel.Workbook '定义工作表对象 Public oldsheet As Excel.Worksheet
'开始 连接 EXCELPrivate Sub Form_Load()
Call JoinExcel
End Sub
Public Sub
JoinExcel()
On Error Resume Next
Set oldxls = GetObject(App.Path, "Excel.Application")
If Err Then Err.Clear
Set oldxls = CreateObject("Excel.Application")
If Err Then
Exit Sub
End If
End If
oldxls.Visible = True
Set oldbook = oldxls.Workbooks.Add
Set oldsheet = oldbook.Worksheets(1)
End Sub
Private Sub Command1_Click() '第二步--执行“打开”对话框
Call OpenExcel
End Sub
Public Sub OpenExcel()
CommonDialog1.Filter = "Excel文件| *.xls"
CommonDialog1.Action = 1
If CommonDialog1.FileName <> "" Then
expath = CommonDialog1.FileName
Workbooks.Open FileName:=expath
oldbook.Close
Else
End If
End Sub
Private Sub Command2_Click() '第三步--执行“保存”对话框
Call SaveExcel
End Sub
Public Sub SaveExcel()
CommonDialog1.Filter = "Excel文件| *.xls"
CommonDialog1.Action = 2
If CommonDialog1.FileName <> "" Then
expath = CommonDialog1.FileName
ActiveWorkbook.SaveAs FileName:=expath
Else
End If
End Sub
(责任编辑:admin)
顶一下
(1)
100%
踩一下
(0)
0%
最新内容
推荐内容