设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2315|回复: 6
打印 上一主题 下一主题

[Access本身] 点击按钮时打开指定的Excel表格,怎么编写按钮的代码

[复制链接]
跳转到指定楼层
1#
发表于 2009-9-30 15:38:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请教各位高手,我想设置一个按钮,这个按钮具有以下功能:当点击按钮时打开指定的Excel表格,这个按钮的代码该如何编写,谢谢大家!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2009-9-30 16:05:35 | 只看该作者
知道的告诉小弟一下方法,万分感激,谢谢大家!
3#
发表于 2009-9-30 16:08:54 | 只看该作者
本帖最后由 todaynew 于 2009-9-30 16:23 编辑

Sub OpenE()
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim strname as String
strname=Inputbox "请输入文件名:"
Set xlBook = xlApp.Workbooks.Open(strname)
xlApp.Application.Visible = True
xlBook.Application.Sheets(1).Select
End Sub
--------------------------------------------------------
如果使用窗体中某控件的变量,则可以
Sub OpenE(strname)
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Set xlBook = xlApp.Workbooks.Open(strname)
xlApp.Application.Visible = True
xlBook.Application.Sheets(1).Select
End Sub

调用:
call openE(me.文件名.value)

------------------------------------------------------
如文件需要查找后打开,则:
Sub OpenE(strname)
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Set xlBook = xlApp.Workbooks.Open(strname)
xlApp.Application.Visible = True
xlBook.Application.Sheets(1).Select
End Sub

Function GetFile() As String
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
With dlgOpen
    .AllowMultiSelect = True
    .Show
End With
GetFile = dlgOpen.SelectedItems(1)
Set dlgOpen = Nothing
End Function

调用:
str=getfile()
call openE(str)
4#
 楼主| 发表于 2009-9-30 16:17:26 | 只看该作者
谢谢无私的帮助,万分感谢!
5#
发表于 2009-9-30 16:24:09 | 只看该作者
不必客气
6#
发表于 2009-9-30 19:35:30 | 只看该作者
shell就行
7#
发表于 2009-10-2 10:15:21 | 只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-21 21:23 , Processed in 0.080510 second(s), 30 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表