Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2231|回复: 2

如何在文件表关闭状态下,取值

[复制链接]
发表于 2014-11-20 11:42 | 显示全部楼层 |阅读模式
求助:
要求:1.两表不同的表
2:B表SHEET,C5取值A表SHEET,A1,
3:A表在关闭状态

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2014-11-20 11:42 | 显示全部楼层
Private Function GetValue(path, filename, sheet, ref)
' 从关闭的工作薄返回值
Dim MyPath As String
'确定文件是否存在
If Right(path, 1) < > "\" Then path = path & "\"
If Dir(path & filename) = "" Then
GetValue = "无法找到指定的Excel文件"
Exit Function
End If
'创建公式
MyPath = "'" & path & "[" & filename & "]" & sheet & "'!" & Range(ref).Range("A1").Address(, , xlR1C1)
'执行EXCEL4宏函数
GetValue = Application.ExecuteExcel4Macro(MyPath)
End Function
'函数参数说明
'-----------------------------------------------------------------
'path:文件路径
'filename:文件名称
'sheet:工作表名称
'ref: 单元格区域
'-----------------------------------------------------------------
Sub GetCloseXlsValue()
Range("C3").Value = GetValue("F:\", "成绩表.xls", "Sheet1", "E8")
End Sub
这个众网上下的,但是做实验的的时候,不行,
回复

使用道具 举报

发表于 2014-11-20 13:55 | 显示全部楼层
本帖最后由 zyouong 于 2014-11-20 13:59 编辑

直接='路径\[A.xls]sheet1'!A1
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-29 20:24 , Processed in 0.305255 second(s), 12 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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