在VBA中,VLOOKUP进入关闭文件尝试打开文件

时间:2016-11-10 00:01:18

标签: excel vba excel-vba vlookup

我试图在两个工作簿之间创建一个vlookup。其中一个是开放的(checkWkbk),另一个是关闭的(cms)。这段代码似乎有效,但它弹出一个窗口"更新值:cms"我必须在cms变量中选择文件集。有没有办法在没有弹出窗口的情况下执行此操作(即,只需完成vlookup而不必查找并选择该文件)?

这是我的代码:

Dim checkWkbk As Workbook, cms As Workbook
Dim exportSheet As Worksheet, dupeSheet As Worksheet
Dim lr As Long

'stuff happens here. exportSheet and dupeSheet 
'are both sheets in checkWkbk, so there's some 
'copying of columns and whatnot that happens before the vlookup    

Set cms = Application.Workbooks.Open("C:\Users\owner\Documents\allAssets.xlsx")

'activate checkWkbk and dupesheet
checkWkbk.Activate
dupeSheet.Select

With ActiveSheet
    lr = .Cells(Rows.Count, 1).End(xlUp).Row

    .Range(.Cells(2, 3), .Cells(lr, 3)).FormulaR1C1 = _
       "=VLOOKUP(RC[-2], cms!C1:C2, 2, FALSE)"
End With

cms.Close SaveChanges:=False

提前感谢您的帮助!我对VBA很新,所以如果我能更好地解释这个问题,请告诉我......

0 个答案:

没有答案