Excel:建立資料夾 VBA 腳本 - 從所選儲存格取得值?

Excel:建立資料夾 VBA 腳本 - 從所選儲存格取得值?

我正在使用 VBA 程式碼在目錄中建立一個新資料夾。我想要做的是從選定的單元格中獲取新的資料夾名稱。我有什麼想法可以做到這一點嗎?

這是我到目前為止的程式碼。

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

答案1

我會嘗試這樣的事情:

Dim folderNameCell As Range
Dim newFolderName As String

Set folderNameCell = Application.Selection
newFolderName = folderNameCell.Value

相關內容