Hallo erst mal
Ich brauche eure hilfe bei einem Code:
Public blnFolderFound As Boolean
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function gUsername() As String
Dim lngLen As Long
Dim strBuffer As String
Const dhcMaxUserName = 255
strBuffer = Space(dhcMaxUserName)
lngLen = dhcMaxUserName
If CBool(GetUserName(strBuffer, lngLen)) Then gUsername = Left$(strBuffer, lngLen - 1)
End Function
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim endRow As Long
Dim rng As Range, c As Range
Dim currPath As String
endRow = Cells(ActiveSheet.Rows.Count, 3).End(xlUp).Row ''Find end row in column C
Set rng = Range(Cells(1, 3), Cells(endRow, 3)) ''check each used cell in column C
For Each c In rng '' For each cell in range
If c.Value <> vbNullString And c.Hyperlinks.Count = 0 Then ''test to see if cell not empty and no hyperlink to speed loop up
Cells(c.Row, 1).Value = Cells(c.Row, 3).Value & "_" & Cells(c.Row, 2).Value ''concatenate the two values
''Test to see if file exists and create on if it doesn't
currPath = ThisWorkbook.Path
If currPath = vbNullString Then currPath = "C:\Users\" & gUsername & "\Desktop" ''save folder to desktop if file isn't saved
folderExists currPath, Cells(c.Row, 1).Value
''if the folder is found, move on to the next cell to check
If blnFolderFound = True Then GoTo nextCellToCheck
''if the folder wasn't found and one was created in the folderExists function, add a hyperlink
ActiveSheet.Hyperlinks.Add Anchor:=c, Address:=currPath & "\" & Cells(c.Row, 1).Value, TextToDisplay:=c.Value
Else: End If
nextCellToCheck:
blnFolderFound = False
Next c
Set rng = Nothing
End Sub
Function folderExists(s_directory As String, s_folderName As String)
Dim obj_fso As Object, obj_dir As Object, obj_folder As Object
Set obj_fso = CreateObject("Scripting.FileSystemObject") '' create a filesystem object
Set obj_dir = obj_fso.GetFolder(s_directory) ''create a folder object
For Each obj_folder In obj_dir.SubFolders '' for each folder in the active workbook's folder
If obj_fso.folderExists(s_directory & "\" & s_folderName) = True Then blnFolderFound = True: Exit For ''see if the file exists
Next
If blnFolderFound = False Then obj_fso.CreateFolder (s_directory & "\" & s_folderName) ''if it doesn't exist create one
Set obj_fso = Nothing
Set obj_dir = Nothing
End Function
Dieser Generiet einen Ordner aus der Zelle C und Zelle B und schreibt in die Zelle C einen Hyperlink: das ist ja eignetlich alles in Ordnung.
Nun meine Problem: Ich würde gerne die Zellen in die ich was eintragen muss und in die der Hyperlink geschreiben wird verändern. Ich versuche dies schon eine ganze Weile aber es funktioniert einfach nicht. Könnte mir jemand sagen wo ich etwas verändern muss das zum Beispiel der Hyperlink in die Zelle F geschrieben würde?
Danke schon mal im Voraus für eure Bemühungen!!
|