gpt4 book ai didi

vba - Excel VBA : Print sheet code not working

转载 作者:行者123 更新时间:2023-12-02 10:54:33 24 4
gpt4 key购买 nike

有人可以帮我吗,我有以下代码:

Sub CreateDealerCopy()
Dim centreid
Dim sheetno As Integer
Dim modelno
Dim modellist As New Collection

Application.ScreenUpdating = False
Sheets("-Summary").Select
centreid = Range("B5").Value
Sheets("-Summary").Copy Before:=Sheets(1)
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Validation.Delete
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 1")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 2")).Select
Selection.Delete
ActiveSheet.Name = "Summary"
Range("A1").Select

Sheets("Model Summary").Select

modellist.Add "field1"
modellist.Add "field2"
modellist.Add "field3"
modellist.Add "field3"
modellist.Add "field5"

sheetno = 1

For Each modelno In modellist
Sheets("Model Summary").Select
Range("B11").Value = modelno
Sheets("Model Summary").Copy After:=Sheets(sheetno)
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Validation.Delete
ActiveSheet.Name = modelno
Range("A1").Select

sheetno = sheetno + 1

Next

Sheets(Array("sheet1", "sheet2", "sheet3", "sheet4", "sheet5", "sheet6")).Copy

ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\NewFolder\" & centreid & "_" & Format$(Date, "(dd-mm-yyyy)") & "_SP" & ".xlsx", _
FileFormat:=51

ActiveWorkbook.Close

Windows("Stock.xlsm ").Activate ""
Sheets(Array"sheet1", "sheet2", "sheet3", "sheet4", "sheet5", "sheet6")).Select
Sheets("sheet1").Activate
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True

'Dim message As Integer
'message = MsgBox("Copy created", vbOKOnly)

End Sub


Sub CreateAllPeople()

Dim people

Sheets("-sheet1").Select

Range("B5").Select

Set people = Range("B5")

Range("AE10").Select

Do While ActiveCell.Value <> ""

people = ActiveCell.Value

Range("B5").Value = people

CreateDealerCopy

ActiveCell.Offset(1, 0).Select

Loop
End Sub

当我尝试运行它时,出现以下错误:

我认为这与以下几行有关,但不确定如何解决问题或问题所在:
Windows("Stock.xlsm ").Activate ""

最佳答案

错误涉及以下行:

Sheets(Array"sheet1", "sheet2", "sheet3", "sheet4", "sheet5", "sheet6")).Select

替换为:
Sheets(Array("sheet1", "sheet2", "sheet3", "sheet4", "sheet5", "sheet6")).Select

正如@David W指出的那样,此行生成相同的错误:
Windows("Stock.xlsm ").Activate ""

它应该是:
Windows("Stock.xlsm").Activate

“Stock.xlsm”中的多余空间会生成下标超出范围错误

关于vba - Excel VBA : Print sheet code not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31165503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com