Excel: crear script VBA de carpeta: ¿obtener valor de la celda seleccionada?

Excel: crear script VBA de carpeta: ¿obtener valor de la celda seleccionada?

Estoy usando un código VBA para crear una nueva carpeta en un directorio. Lo que quiero hacer es obtener el nuevo nombre de la carpeta de la celda seleccionada. ¿Alguna idea de cómo puedo hacer esto, por favor?

Aquí está el código que tengo hasta ahora.

If Target.Column = Range("B1").Column Then
  If Target.Row > 7 Then

'Variable definitions
Dim FolderListRange As Range
Dim FolderRange As Variant
Dim FolderName As String
Dim ParentFolderPath As String

On Error GoTo Handle
    ' Set the Folder where the individual folders should be created
    ParentFolderPath = "\\UKSH000-FILE06\purchasing\New Supplier Set-Ups"

    Set FolderListRange = Range("B" & Target.Row).SpecialCells(xlCellTypeConstants)

    For Each FolderRange In FolderListRange

        FolderName = ParentFolderPath & "\" & FolderRange.Value

        If FileSystem.Dir(FolderName, vbDirectory) = vbNullString Then
            FileSystem.MkDir FolderName
        End If

Continue:
    Next

Handle:
  End If
  End If

Respuesta1

Yo intentaría algo como esto:

Dim folderNameCell As Range
Dim newFolderName As String

Set folderNameCell = Application.Selection
newFolderName = folderNameCell.Value

información relacionada