excel - 当 ActiveWorkbook.Close 发生时,程序主体中的更改不会被保存
问题描述
我有一个 VBA 程序,它打开一个 .txt 文件并对某些行/列进行一些搜索,突出显示这些行/列,然后执行 ActiveWorkbook.SaveAs。我遇到的问题是当我跟进“ActiveWorkbook.Close SaveChanges:=True”时更改没有保存在此先谢谢斯科特
Option Explicit
Sub Import_txt()
Dim i As Long
Dim x As Long
Dim y As Long
Dim z As Long
' Import_txt Macro
'
'
ChDir "C:\Users\parsons_s\Desktop\Verity II\G5_KLARF"
Workbooks.OpenText Filename:= _
"C:\Users\parsons_s\Desktop\Verity II\G5_KLARF\G5_KLARF.txt", Origin:=437, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _
, 1), Array(4, 1)), TrailingMinusNumbers:=True
'Find_txt Macro
Cells.Find(What:="SampleTestPlan", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
x = ActiveCell.Offset(0, 1)
y = ActiveCell.Row + 1
z = ActiveCell.Row + 16
i = 0
With ActiveSheet
'Shade Field Actions Blue
Do While i < x
Cells(y + i, 2).Interior.ColorIndex = 37
Cells(y + i, 3).Interior.ColorIndex = 37
i = i + 1
Loop
Cells(z, 3).Interior.ColorIndex = 37
Cells(z, 4).Interior.ColorIndex = 37
End With
ActiveWorkbook.SaveAs Filename:="C:\Users\parsons_s\Desktop\Verity II\G5_KLARF\G5_KLARF_Find_locations.xls"
'ActiveWorkbook.Close SaveChanges:=True
Windows("KLARF converter.xlsm").Activate
End Sub
解决方案
推荐阅读
- php - 发送邮件时在视图文件中显示数据
- javascript - NodeJS 错误“不能在模块外使用 import 语句”
- c# - 没有适用于 MVC 3 的 Sustainsys.Saml2?有没有其他选择?
- graph - 图数据库中的建模时间
- python - 这些功能是如何实现的?
- powershell - Powershell远程:具有嵌套函数的函数
- java - 为什么 apache http 客户端比 java 中的 URL.openConnection 慢 2 倍?
- mysql - 如何在存在时选择列的值
- android - Room:错误:不确定如何将 Cursor 转换为此方法的返回类型(void)
- c++ - 将 bmp 文件加载到 TSpeedButton