2012-11-13 162 views
0

可能重複:
Extracting the hyperlink from multiple cells with VBAExcel的腳本超鏈接提取

[固定]排序它自己:)

對於i = 3要總

Cells(i, 11) = Cells(i, 1).Hyperlinks.Item(1).Address 
Cells(i, 12) = Cells(i, 2).Hyperlinks.Item(1).Address 

Next i 

我從來沒有在Excel中做任何腳本,所以任何幫助表示讚賞。

我想提取從列1 & 2.超鏈接地址(URL),並將其粘貼(而不是超鏈接)到另一列(這樣我就可以導出爲CSV的鏈接)

我想要做的事像循環一樣,但它不起作用!

ActiveSheet.Cells(i, 11).Value = ActiveSheet.Cells(i, 1).Hyperlinks.Item(1).Address 


ActiveSheet.Cells(i, 12).Value = ActiveSheet.Cells(i, 2).Hyperlinks.Item(1).Address 

謝謝!

回答

0

下面是如何獲取表單前兩列中的所有超鏈接並將其寫入下一張表的示例。

Sub getHyperlinks() 
'used to keep track of where we are at when writing to the second sheet 
Dim iWriteRow As Long 
'used to hold how many columns to look through 
Dim numberOfCols As Long 
numberOfCols = 2 
'set initial position 
iWriteRow = 1 

'variable used in looping through the hyperlinks 
Dim h As Hyperlink 
'loop through all hyper links on the sheet 
For i = 1 To numberOfCols 
    For Each h In ActiveWorkbook.Sheets(1).Columns(i).Hyperlinks 
     'write them to the next sheet 
     ActiveWorkbook.Sheets(2).Cells(iWriteRow, i).Value = h.Address 
     'add 1 to our counter 
     iWriteRow = iWriteRow + 1 
    Next 
    iWriteRow = 1 
Next i 
End Sub