尝试打开文件的VBA下标超出范围错误

时间:2019-04-12 15:54:07

标签: excel vba

我试图打开一个文件,然后找到最后一行,一切工作到这一行:

  

设置SourceSheet = crWorkbook.Worksheets(“现金申请表”)

它给我一个下标超出范围的错误,我不知道为什么...

 Dim filter As String
 Dim caption As String
 Dim crFilename As String
 Dim crWorkbook As Workbook
 Dim crMasterWorkbook As Workbook

 ' make weak assumption that active workbook is the target
 Set crMasterWorkbook = Application.ActiveWorkbook

 With Application.FileDialog(msoFileDialogFilePicker)
 .AllowMultiSelect = False
 .InitialFileName = "*Cash Report*.xlsx"
 .Show
 crFilename = .SelectedItems(1)

 End With

 ' get the cash request workbook
 'caption = "Please Select an input file "
 'crFilename = Application.GetOpenFilename(filter, , caption)

 Set crWorkbook = Application.Workbooks.Open(crFilename, UpdateLinks = False)

 ' copy data from source to target workbook
 Dim targetSheet As Worksheet
 Set targetSheet = crMasterWorkbook.Worksheets("Master Cash Request Log")
 Dim SourceSheet As Worksheet
 Set SourceSheet = crWorkbook.Worksheets("Cash Request Form")

 'Define last row
 target_lastrow = targetSheet.Range("A1").CurrentRegion.Rows.Count

0 个答案:

没有答案