ActiveWorkbook.Close发生时不会保存程序主体中的更改

时间:2019-03-12 16:19:22

标签: excel vba

我有一个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

0 个答案:

没有答案