VBA宏不适用于XLS兼容模式`

时间:2018-11-19 14:47:52

标签: excel vba xlsx xls backwards-compatibility

此宏使用w.xlsx文件打开两个参考文件,以使用“样式”作为主键提取不同的描述性数据。它从活动单元的左到右搜索,并引用第一个有效的“样式”(使用“ Stylemaster.xlsx”文件作为词典)来查找最后插入活动单元的Vlookup方程。

此命令中是否有不能用于.XLS文件的命令?或者我在这里想念什么。

这两个文件将在执行后打开和隐藏,而do while将执行,但是活动单元将保留为空白。

Sub StyleINVLookLeft()
Dim form
Dim x As Workbook
Dim wb As Workbook
Dim col As Integer
Dim leng As Integer
Dim cel
Dim flg


Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.DisplayAlerts = False

On Error Resume Next
    Set wb = Workbooks("INV Master.xlsx")
    If Err Then
    wb = Workbooks.Open("J:\INV Master.xlsx")
    End If

On Error Resume Next
    Set x = Workbooks("BC Style Master ALL2.xlsx")
    If Err Then
    x = Workbooks.Open("J:\BC Style Master ALL2.xlsx")
    End If

If Right(ActiveWorkbook.Path, 3) = "xls" Then
flg = 1
col = -1
GoTo Skipsearch
End If


flg = 0
col = -13

TryAgain:

col = col + 1

With ActiveCell
    On Error Resume Next
    cel = ActiveCell.Offset(0, col)
    leng = Len(cel)
        Do While leng <> 6 And col > -13 And col < 12
        col = col + 1
            On Error Resume Next
        cel = ActiveCell.Offset(0, col)
        leng = Len(cel)
            If col > 300 Then MsgBox "Error: Infinite Loop Triggered"
            If col > 300 Then End
        Loop

If col >= 12 And leng <> 6 Then
    col = -1
    flg = 1
End If

End With

Skipsearch:

If IsError(Application.VLookup(cel, x.Worksheets("Sheet1").Range("a:A"), 1, 0)) And flg = 0 Then
    GoTo TryAgain
End If

ActiveCell.formula = "=VLOOKUP(RC[" & col & "],'[INV Master.xlsx]Style INV'!c1:c8,7,FALSE)"
            form = Left(ActiveCell.formula, 9) & "$" & Right(ActiveCell.formula, Len(ActiveCell.formula) - 9)
            ActiveCell.Select
            ActiveCell.formula = form
            form = ""

Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

Workbooks("INV Master.xlsx").Windows(1).Visible = False
Workbooks("BC Style Master ALL2.xlsx").Windows(1).Visible = False

End Sub

0 个答案:

没有答案