2013-04-12 100 views
1

我試圖將excel電子表格中的所有超鏈接拖入新的工作表中。我希望列A顯示超鏈接中的文本,列B顯示超鏈接地址。VBA超鏈接名稱和地址

我已經編寫了下面的代碼,並且列B的所有工作正常,但列A中的值不會全部過來,並且它們不匹配列B中的超鏈接地址。我在做什麼錯誤?

在此先感謝

Sub extract_links() 
    Dim hyp As Hyperlink 
    Dim ReadCols As Long 
    Dim ReadWriteRow As Long 
    ReadWriteRow = 1 
    ReadCols = 6 

ActiveWorkbook.Sheets(2).Range("a:b").Clear 

For c = 1 To ReadCols 
    For Each hyp In ActiveWorkbook.Sheets(1).Columns(c).Hyperlinks 
     ActiveWorkbook.Sheets(2).Range("a" & ReadWriteRow).Value = ActiveWorkbook.Sheets(1).Cells(ReadWriteRow, c).Value 
     ActiveWorkbook.Sheets(2).Range("b" & ReadWriteRow).Value = hyp.Address 
     ReadWriteRow = ReadWriteRow + 1 
    Next 
Next c 
End Sub 

回答

2

這時候你需要改變這一點:

ActiveWorkbook.Sheets(2).Range("a" & ReadWriteRow).Value = ActiveWorkbook.Sheets(1).Cells(ReadWriteRow, c).Value 

到這一點:

ActiveWorkbook.Sheets(2).Range("a" & ReadWriteRow).Value = hyp.Range.Value 
+0

感謝您的幫助了! – Doug

+0

不客氣:) –

+0

+ 1好一個:) –