将范围复制到新的工作簿 FileDialog 提示不起作用
Copying Range into new Workbook FileDialog prompt not working
我正在尝试将一些特定的单元格复制到一个新的工作簿中,系统提示我在 运行 VBA 脚本时创建该工作簿。我不断收到 Object doesn't support this 属性 or method on wsI.Range("Y2:AF2882),我的代码有什么问题?
Option Explicit
Sub Export1()
Dim wbI As Workbook, wbO As Workbook
Dim wsI As Worksheet, wsO As Worksheet
Dim Filename As Variant
Set wbI = ThisWorkbook
Set wbO = Workbooks.Add
Filename = Application.GetSaveAsFilename(Filename, "Excelfile (*.xlsx), *.xlsx")
With wbO
Set wsO = wbO.Sheets("Ark1")
Set wsI = wbI.Sheets("SVK stationer")
.SaveAs Filename
wsI.Range("Y2:AF2882") _
.AutoFilter Field:=1, Criteria1:="<>"
.SpecialCells(xlCellTypeVisible).Copy
wsO.Range("A1").PasteSpecial (xlPasteValuesAndNumberFormats)
End With
End Sub
更新评论
Option Explicit
Sub Export1()
Dim wb As Workbook
Set wb = Workbooks.Add
wb.Sheets(1).Name = "Arki"
With ThisWorkbook.Sheets("SVK stationer").Range("Y2:AF2882")
.AutoFilter Field:=1, Criteria1:="<>"
.SpecialCells(xlCellTypeVisible).Copy
wb.Sheets(1).Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
wb.SaveAs Application.GetSaveAsFilename("", "Excelfile (*.xlsx), *.xlsx")
'wb.Close False
End With
End Sub
我正在尝试将一些特定的单元格复制到一个新的工作簿中,系统提示我在 运行 VBA 脚本时创建该工作簿。我不断收到 Object doesn't support this 属性 or method on wsI.Range("Y2:AF2882),我的代码有什么问题?
Option Explicit
Sub Export1()
Dim wbI As Workbook, wbO As Workbook
Dim wsI As Worksheet, wsO As Worksheet
Dim Filename As Variant
Set wbI = ThisWorkbook
Set wbO = Workbooks.Add
Filename = Application.GetSaveAsFilename(Filename, "Excelfile (*.xlsx), *.xlsx")
With wbO
Set wsO = wbO.Sheets("Ark1")
Set wsI = wbI.Sheets("SVK stationer")
.SaveAs Filename
wsI.Range("Y2:AF2882") _
.AutoFilter Field:=1, Criteria1:="<>"
.SpecialCells(xlCellTypeVisible).Copy
wsO.Range("A1").PasteSpecial (xlPasteValuesAndNumberFormats)
End With
End Sub
更新评论
Option Explicit
Sub Export1()
Dim wb As Workbook
Set wb = Workbooks.Add
wb.Sheets(1).Name = "Arki"
With ThisWorkbook.Sheets("SVK stationer").Range("Y2:AF2882")
.AutoFilter Field:=1, Criteria1:="<>"
.SpecialCells(xlCellTypeVisible).Copy
wb.Sheets(1).Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
wb.SaveAs Application.GetSaveAsFilename("", "Excelfile (*.xlsx), *.xlsx")
'wb.Close False
End With
End Sub