|
各位大神,请问Excel 根据不同的应用场景,从母版工作薄条件选择不同的工作表格另存为新的工作薄 VB该如何编写? 跪求各位大神帮忙解答。谢谢~!
网络上查找的代码东拼西凑如下:
Sub 另存为()
Dim sh As Worksheet, m&
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim i As Long
With Sheets("Sheet1")
For i = 1 To 11 '工作薄一共有11个sheet
If .Cells(15, Chr(i + 98)) = "√" Then '11个单元格内容与11个一一sheet对应,根据√来判断sheet是否保存
jj = Cells(14, Chr(i + 98)).Value '若是改成Then Sheets(Cells(14, Chr(i + 98)).Value).Copy,循环条件选择,最终选择好的所有Sheet全部另存为又该如何编写
For Each sh In Worksheets
If sh.Visible = xlSheetVisible And sh.Name = "jj" Then
m = m + 1
If m = 1 Then sh.Select Else sh.Select False
End If
Next
ActiveWindow.SelectedSheets.Copy
For Each sh In Worksheets
sh.Unprotect
With sh.UsedRange
.Value = .Value
End With
Next
FileSource = Range("D10") 'sheet1 D10单元格有新的存储路径
.SaveAs Filename:=FileSource & "\" & Range("D9").Value & ".xls", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
' 每次另存为名字根据Sheet1 D9单元格内容命名。另存为的工作薄最好无VBA代码
Application.ScreenUpdating = True
End If
Next
End With
End Sub
|
|