首页 > 解决方案 > 当 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

标签: excelvba

解决方案


推荐阅读