[英]Open new file and quit without saving
I have this subroutine, I would like to quit without save from AAAAMMGG_A.xls我有这个子程序,我想退出而不保存 AAAAMMGG_A.xls
Thanks谢谢
Sub A_STEP3()
On Error GoTo Err_A_STEP3
Dim rng As Range
Dim rng2 As Range
Dim c As Range
Dim d As Range
Dim righedacopiare As Integer
'open the file AAAAMMGG_A.xls di Flutitoli e copio le informazioni
Workbooks.Open (MyPath2 & nomefile2(8))
Range("A2:W2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
ActiveWorkbook.Close SaveChanges:=False
Windows("modello.xlsm").Activate
Sheets("A").Select
Range("C3").Select
ActiveSheet.Paste
righedacopiare = 1000
' formatto le stringhe in numero
Set rng = Worksheets("A").Range("U3:V" & righedacopiare)
For Each c In rng
c.Value = c.Value * 1
c.HorizontalAlignment = xlRight
Next
Set rng2 = Worksheets("A").Range("C3:F" & righedacopiare)
For Each d In rng2
d.Value = "'" & d.Value
Next
Exit_A_STEP3:
Exit Sub
Err_A_STEP3:
MsgBox "A_STEP3 -> " & Err.Number & ": " & Err.Description
ERROREBLOCCO = True
Resume Exit_A_STEP3
End Sub
First, make sure that you are capturing the new workbook in a variable so that you can specify which workbook you want to close:首先,确保您在变量中捕获新工作簿,以便您可以指定要关闭的工作簿:
Dim wb_A As Workbook
Set wb_A = Workbooks.Open MyPath2 & nomefile2(8)
'Do stuff here
wb_A.Close SaveChanges:=False
Second, if you don't want to save, you can open the workbook in Read-Only mode:其次,如果不想保存,可以以只读模式打开工作簿:
Dim wb_A As Workbook
Set wb_A = Workbooks.Open MyPath2 & nomefile2(8), ReadOnly:=True
'Do stuff here
wb_A.Close SaveChanges:=False
Using ActiveWorkbook
is messy - always try to use full object paths (ie Worksheet_Name.Range(..)
instead of just Range(..)
or ActiveSheet.Range(..)
where possible to avoid unexpected activity使用
ActiveWorkbook
很麻烦 - 总是尝试使用完整的对象路径(即Worksheet_Name.Range(..)
而不仅仅是Range(..)
或ActiveSheet.Range(..)
尽可能避免意外活动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.