2013-10-03 1 views
1

오늘 코드를 하이퍼 링크로 고정 시켰지만 열 A 대신 열 U에 목록을 넣는 방법을 알아낼 수 없습니다.디렉터리 목록 하이퍼 링크 매크로를 다른 열로 이동해야합니다.

Sub hyperlinker() 

    Dim MOG As Object 
    Dim rsMOG As Object 
    Dim PrimeF As Object 
    Dim Bit As Object 
    Dim Foder As Object 
    Dim Linger As Integer 
    Dim Enigma As String 
    Dim Way As String 


    'Get the current folder 
    Set MOG = CreateObject("scripting.filesystemobject") 
    Set PrimeF = MOG.GetFolder(ThisWorkbook.Path) 
    Set MOG = Nothing 

    'Get the row at which to insert 
    Linger = Range("A65536").End(xlUp).row + 1 

    'Create the recordset for sorting 
    Set rsMOG = CreateObject("ADODB.Recordset") 
    With rsMOG.Fields 
    .Append "Way", 200, 200 
    .Append "Enigma", 200, 200 
    .Append "Bit", 200, 200 
    End With 
    rsMOG.Open 

    ' Traverse the entire folder tree 
    TraverseFolderTree PrimeF, PrimeF, rsMOG 
    Set PrimeF = Nothing 

    'Sort by type and name 
    rsMOG.Sort = "Bit ASC, Enigma ASC " 
    rsMOG.MoveFirst 

    'Populate the first column of the sheet 
    While Not rsMOG.EOF 
    Enigma = rsMOG("Enigma").value 
    Way = rsMOG("Way").value 
    If (Enigma <> ThisWorkbook.name) Then 
     ActiveSheet.Hyperlinks.Add Anchor:=Cells(Linger, 1), Address:=Way, TextToDisplay:=Enigma 
     Linger = Linger + 1 
    End If 
    rsMOG.MoveNext 
    Wend 

    'Close the recordset 
    rsMOG.Close 
    Set rsMOG = Nothing 

End Sub 

Private Sub TraverseFolderTree(ByVal parent As Object, ByVal node As Object, ByRef rs As Object) 

    'List all files 
    For Each Bit In node.Files 

    Dim Enigma As String 
    Enigma = Mid(Bit.Path, Len(parent.Path) + 2) 

    rs.AddNew 
    rs("Way") = Way 
    rs("Enigma") = Enigma 
    rs("Bit") = "Bit" 
    rs.Update 
    Next 

    'List all folders 
    For Each Foder In node.SubFolders 
    TraverseFolderTree parent, Foder, rs 
    Next 

End Sub 

철자 색인에있는 임의의 단어를 다른 매크로에서 일반적인 단어를 사용하기 때문에 이상한 이름으로 변경해야했습니다. 기본적으로

,

dim linger as integer 

'Get the row at which to insert 
    Linger = Range("A65536").End(xlUp).row + 1 

가 열 A에게 나에게 내가 거기에 넣어 무슨 이잖아요주지, 사람이 열 U이 하이퍼 링크 목록을 얻을하는 데 도움이 수 있습니까?

+0

여기에 내가 마지막으로 대답하는 링크가 있습니다. 내 매크로를 수정하여 디렉토리 목록을 하이퍼 링크로 연결하십시오. http://exackoverflow.com/questions/19148596/excel-macro-listing-all-files-within-the-contained-directory-and-hyperlinking-th –

답변

1

U21의 색인을 보유합니다. Cells 객체를 사용하여 첫 번째 매개 변수가있을 때

그래서

ActiveSheet.Hyperlinks.Add Anchor:=Cells(Linger, 1), Address:=Way, TextToDisplay:=Enigma 

ActiveSheet.Hyperlinks.Add Anchor:=Cells(Linger, 21), Address:=Way, TextToDisplay:=Enigma 

로 교체하고 열에서 하이퍼 링크를 얻을 수 있어야 U


보기 행 번호, 두 번째 열 번호입니다.

그래서 Cells(1,1)Range("A1")

Cells(linger,21)linger의 값 U

또는

Range("U" & linger) 대안

것이다 열에 무엇이든 될 바와 같다 A1에 대응
+0

도움을 주셔서 대단히 감사드립니다. 매력처럼 작동합니다. 그리고 지금 나는 내일을 위해 모두 준비가되어있다 = P 좋은 밤 –

관련 문제