Excel Vba

来源:互联网 发布:国外叫停近视手术知乎 编辑:程序博客网 时间:2024/06/10 08:20
 Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err
Dim wb As Workbook
Dim StrCell, StrCell2, StrCell3, StrFlod, StrWorkbook As String
 
    With Application
      .ScreenUpdating = False
      .EnableEvents = False
      
   
      StrCell = Cells(1, 1).Value
      StrCell2 = Cells(2, 1).Value
      StrCell3 = Cells(3, 1).Value
      StrFlod = "D:/TEST"
      Cells(1, 2) = StrFlod
   
      StrWorkbook = "/" & StrCell & "-" & StrCell2 & "-" & StrCell3 & ".xls"
      Set wb = Workbooks.Open(StrFlod & StrWorkbook, True, True)
                  
      Cells(2, 2) = StrFlod & StrWorkbook
      Cells(3, 2) = wb.Worksheets(StrCell & "-" & StrCell2 & "-" & StrCell3).Cells(1, 1)
        
      Cells(4, 2) = Application.WorksheetFunction.VLookup(Cells(5, 1), Workbooks(StrFlod & StrWorkbook).Worksheets(StrCell & " - " & StrCell2 & " - " & StrCell3).Range("A1:B46"), 2, False)
         wb.Close False
         Set wb = Nothing
   
          .EnableEvents = True
     .ScreenUpdating = True
    End With
    Exit Sub
原创粉丝点击