
Option Explicit
Sub CreaFile()
Dim i As Integer
Dim Percorso As String
Dim NomeFile As String, ValCella As String
Dim Esiste As String
Dim Indice As Integer
Percorso = "D:File Creati" '<<<< Da modificare col percorso desiderato
For i = 1 To 300
If Range("A" & i).Value <> "" Then
ValCella = Range("A" & i).Value
NomeFile = Percorso & ValCella & ".xlsx"
Esiste = Dir(NomeFile)
Workbooks.Add
If Esiste = "" Then
ActiveWorkbook.SaveAs Filename:=NomeFile
Else
Indice = Indice + 1
NomeFile = Percorso & ValCella & " (" & Indice & ").xlsx"
ActiveWorkbook.SaveAs Filename:=NomeFile
End If
ActiveWorkbook.Close (True)
End If
Next i
End Sub
|
Sub CreaFile()
Dim i As Integer
Dim Percorso As String
Dim NomeFolder As String
Dim NomeFolderOrig As String
Dim ValCella As String
Dim Esiste As String
Dim Indice As Integer
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Percorso = "D:File Creati" '<<<< Da modificare col percorso desiderato della cartella padre
Set f = fs.GetFolder(Percorso)
For i = 1 To 300
If Sheets(1).Range("A" & i).Value <> "" Then
ValCella = Sheets(1).Range("A" & i).Value
NomeFolderOrig = Percorso & ValCella
NomeFolder = NomeFolderOrig
Indice = 0
Do
Esiste = fs.FolderExists(NomeFolder)
If Esiste Then
Indice = Indice + 1
NomeFolder = NomeFolderOrig & "_" & Indice
Else
fs.CreateFolder (NomeFolder)
Exit Do
End If
Loop
End If
Next i
End Sub
|
