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