用数据创build,命名和填充新的工作簿

我有一个包含两列数据的Excel工作表。 列A具有所需的新工作簿名称,列B的相邻单元格具有我在新工作簿中需要的数据。

因此,如果032411在列A中,并且50在列B中,则该macros将创build一个名为032411的新工作簿,并且50将位于该工作簿的单元格A1中。

你可以使用这个:

 Sub CreateBooks() Dim oCell As Excel.Range Dim oWorkbook As Excel.Workbook 'Added to avoid messages asking to confirm overwriting ' previous existent files with same name Application.DisplayAlerts = False For Each oCell In Range("A:A") If oCell.Value = "" Then Exit For Set oWorkbook = Workbooks.Add oWorkbook.Sheets(1).Cells(1, 1).Value = oCell.Offset(0, 1).Value 'If the cell value contains only the file name (instead of the whole path ' the file needs to be saved) it will save into MyDocuments folder oWorkbook.Close True, oCell.Value Next oCell Application.DisplayAlerts = True End Sub 

如果你有几个文件要生成,你可以使用application.ScreenUpdating = False