VBA错误' 91' - 找不到错误来源

时间:2017-05-24 19:06:16

标签: excel vba excel-vba

我试图打开文件来访问第三张工作表中的信息。 .FileDialog工作正常,我可以选择一个文件,但由于代码段底部附近的run-time error '91'Set wbR = wb.Worksheets(3),我不断收到wb.Worksheets(3) = <Object variable or With block variable not set>因为Set wb = Workbooks.Open(myFile)。这导致我相信我的Nothing不起作用并返回.FileDialog,但在查看了其他人如何使用'Set variables Dim wb As Workbook 'Workbook to open Dim wbR As Worksheet 'This is the raw data on the new workbook Dim wsL As Worksheet 'Worksheet in current file Dim myFile As String 'File to open Dim FilePicker As FileDialog 'Set light chain hit worksheet Set wsL = ThisWorkbook.Worksheets(3) 'Optimizes Speed Application.ScreenUpdating = False Application.EnableEvents = False Application.Calculation = xlCalculationManual 'Retrieve target file Set FilePicker = Application.FileDialog(msoFileDialogFilePicker) 'Opens folder-picking window With FilePicker .Title = "Select a file." .AllowMultiSelect = False If .Show <> -1 Then GoTo NextCode myFile = Dir(.SelectedItems(1)) End With 'If folder is not selected NextCode: myFile = myFile If myFile = "" Then GoTo ResetSettings 'Set variable equal to opened workbook Set wb = Workbooks.Open(myFile) 'Ensure Workbook has opened before moving on to next line of code DoEvents 'Sets worksheet for importing Set wbR = wb.Worksheets(3) 打开文件后,我无法看到我的afade是如何不同的并且不会发挥作用。任何帮助或建议将不胜感激。

ffmpeg -i input.mp4 \
    -filter_complex \
        "[0:v]fade=t=out:st=1798:d=1[v]; \
         [0:a]afade=t=out:st=1798:d=1[a]" \
     -map "[v]" -map "[a]" output.mp4

*宏继续超过最后一行,但由于此错误,它还没有到达

1 个答案:

答案 0 :(得分:0)

抱歉,我必须使用答案框来执行此操作,因为涉及代码。但不,你做得很好。这是调试的工作原理。既然我们知道哪些线路不起作用,我们将尝试找出原因。现在尝试改变

wsL = ThisWorkbook.Worksheets(3) 

wsL = ThisWorkbook.Worksheets(1) 

wsL = ThisWorkbook.Worksheets("PUTnameOFsheetHere") 

查看是否设置。如果是这样,那么我们知道WorkSheets存在某种问题(3)。

现在我们将尝试找到原因&#34;设置wb = Workbooks.Open(myFile)&#34;不管用。你的宏观录音上的Tunr。得到&#34;文件&#34;在菜单上选择&#34;打开。&#34;对话框将打开。在对话框中搜索您的文件并将其打开。返回原始工作簿并停止录制。找到录制的宏,您将看到Excel用于打开文件的确切行。它应该是这样的:

Workbooks.Open Filename:="C:\Files\CNC TEST.xlsx"

现在用PF8运行你的脚本并将鼠标悬停在&#34; myFile&#34;初始化后。它的值是否与录制的宏文件的路径和文件名匹配?