Sub ScreenTip()
Dim hl As Hyperlink
For Each hl In ActiveSheet.Hyperlinks
hl.ScreenTip = CStr(hl.Range.Value)
Next
End Sub
我有此代碼,但它只能在您當前所在的Worksheet上運行。我希望它可以遍歷整個工作簿。我將如何改變這一點呢?將宏從工作表應用到工作簿
Sub ScreenTip()
Dim hl As Hyperlink
For Each hl In ActiveSheet.Hyperlinks
hl.ScreenTip = CStr(hl.Range.Value)
Next
End Sub
我有此代碼,但它只能在您當前所在的Worksheet上運行。我希望它可以遍歷整個工作簿。我將如何改變這一點呢?將宏從工作表應用到工作簿
更改For Each
,並添加一個新的變量
Sub ScreenTip()
Dim hl As Hyperlink
Dim ws as WorkSheet
For Each ws in ActiveWorkbook.Worksheets
For Each hl In ws.Hyperlinks
hl.ScreenTip = CStr(hl.Range.Value)
Next hl
Next ws
End Sub
Sub ScreenTip()
Dim hl As Hyperlink
dim sh as worksheet
dim bk as workbook
set bk = whateverbook
for each sh in bk.sheets
For Each hl In sh.Hyperlinks
hl.ScreenTip = CStr(hl.Range.Value)
Next hl
next sh
End Sub
LOL可樂在你身上! – Hrothgar
它說,然後類型不匹配突出hl.ScreenTip = CStr的(hl.Range.Value) –
@MichaelDowney我不能告訴你爲什麼,它對我來說工作得很好。你有沒有嘗試用調試器一次一步地穿過它?另外值得注意的是,我沒有更改那條拋出錯誤的代碼,這是你原來的帖子。 – PartyHatPanda
有另一個Excel文件打開導致問題。 –