VBA各种超链接代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
功能:
遍历指定路径中的文件夹,并在当前工作表中添加超链接
Sub c hiefz jh1()
Dimi%, r%, mF dr$,mPth$, aDr s()
r = 1
mpath = "h:\"
m Fdr = Dir(mpath, vbD irect ory)
Do Wh ile m Fdr <> ""
If mF dr <> "."And m Fdr <> ".." The n
If G etAtt r(mpa th &mFdr) = 16 Then 'f older=16,f ile=32
ReDim Pres erveaDrs(1 Tor)
aDrs(r) = mpat h & m Fdr
r = r +1
EndIf
En d If
mFdr= Dir
Loop
With Acti veShe et
For i =1 Tor - 1
.Hyper links.Addancho r:=.C ells(i, 1), Add ress:=aDrs(i) Ne xt i
End W ith
E raseaDrs
End S ub
**********Re mark***************
常数值描述
v bNorm al 0 常规
vb ReadO nly 1 只读
vb Hidde n 2隐藏
vbS ystem4系统文件
vb Direc tory16 目录或文件夹
v bArch ive 32 上次备份以后,文件已经改变vbal ias 64 指定的文件名是别名。
======================================
======================================
功能:
遍历本路径中的文件,并在当前工作表1A列中添加超链接Sub chie fzjh2()
Di m mNm$, mP th$,dic,r%
Se t dic = Cr eateO bject("scr iptin g.dic tiona ry")
mPth= "c:\"
mN m = D ir(mP th &"*.*")
DoWhile mNm<> ""
If Ge tAttr(mPth & mN m) =32 Th en di c.Add mNm, ""
mN m = D ir
Lo op
[a1].Re size(dic.C ount, 1) = Work sheet Funct ion.T ransp ose(d ic.ke ys)
W ith S heet1
For r = 1To di c.Cou nt
.Hyp erlin ks.Ad d anc hor:=Cells(r, 1), Ad dress:=mPt h & .Cells(r, 1).Tex t
Next
EndWith
End S ub
======================================
======================================
功能:
遍历本工作簿中所有工作表,并在当前工作表1A列中添加超链接
Subchief zjh3()
Wit h She et1
[a1] = "She ets L ink:"
For i% = 2 To W orksh eets.Count
.Hyper links.Addancho r:=Ce lls(i, 1), Addr ess:="", _
S ubAdd ress:=Shee ts(i).Name & "!a1",TextT oDisp lay:=Sheet s(i).Name
N ext i
EndWith
End S ub
======================================
======================================
功能:
更改数据有效性设置后,把有效性不规范的单元格地址在表2中写出来,
并超链接
'活动单元格先定位于含有有效性的单元格,再运行这段宏,以取得有效性内容Sub c hiefz jh4()
Appl icati on.Sc reenU pdati ng =False
DimtSt$, i%,mC%,r%, S ht$,mAdd(), mF ml$
m C = A ctive Cell.Colum n
Sht = Ac tiveS heet.Name
tSt = Acti veCel l.Val idati on.Fo rmula1
For i =1 ToActiv eCell.End(xlDow n).Ro w
If I nStr(tSt,Cells(i, m C).Te xt) = 0 Th en
r =r + 1
R eDimPrese rve m Add(1 To r)
mAdd(r) =Cells(i, m C).Ad dress(0, 0)
EndIf
Ne xt i
'结果输出到shee t2 A列,从第一行开始,自行修改
Sh eet2.Activ ate
C olumn s(1).Clear Conte nts
W ith A ctive Sheet
For i = 1To r
.Hyper links.AddAncho r:=.C ells(i, 1), Add ress:="",_
SubA ddres s:=Sh t & "!" &mAdd(i), T extTo Displ ay:=m Add(i) Next i
En d Wit h
App licat ion.S creen Updat ing = True
EndSub
。