Excel精英培训网

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

[已解决]根据条件超连接到指定目录下的工作表

[复制链接]
发表于 2017-4-8 22:57 | 显示全部楼层 |阅读模式
Private Sub CommandButton1_Click()
   Dim f$, th$
    th = ThisWorkbook.Path & "\" & [c8].Value & "\"
    f = Dir(th & [c6].Value & "*.xls*")
    If Len(f) Then
        Workbooks.Open (th & f)
    Else
        MsgBox "文件不存在!"
    End If
End Sub
此代码是根据表C6文件夹名称,C8工作表名称超连接到指定目录下的指定工作表。
我想设个:当表一B5=表二C5时才超连接到指定目录下的工作表,不等时提示“与表二不符”。
请各位帮忙,谢谢!

最佳答案
2017-4-12 11:52
我猜的
  1. Private Sub CommandButton1_Click()
  2.   Dim f$, th$
  3.   If Sheets(1).[b5].Value = Sheets(2).[c5].Value Then
  4.     th = ThisWorkbook.Path & "" & [c8].Value & ""
  5.     f = Dir(th & [c6].Value & "*.xls*")
  6.     If Len(f) Then
  7.       Workbooks.Open (th & f)
  8.     Else
  9.       MsgBox "文件不存在!"
  10.     End If
  11.   Else
  12.     MsgBox "与表二不符"
  13.   End If
  14. End Sub
复制代码
发表于 2017-4-12 11:52 | 显示全部楼层    本楼为最佳答案   
我猜的
  1. Private Sub CommandButton1_Click()
  2.   Dim f$, th$
  3.   If Sheets(1).[b5].Value = Sheets(2).[c5].Value Then
  4.     th = ThisWorkbook.Path & "" & [c8].Value & ""
  5.     f = Dir(th & [c6].Value & "*.xls*")
  6.     If Len(f) Then
  7.       Workbooks.Open (th & f)
  8.     Else
  9.       MsgBox "文件不存在!"
  10.     End If
  11.   Else
  12.     MsgBox "与表二不符"
  13.   End If
  14. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 13:23 , Processed in 0.255550 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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