vba - 下一个没有?

标签 vba compiler-errors syntax-error

我确定已经问了一百遍了,并且已经将它与其他类似的方法进行了比较,但是我在代码中看不到问题。现在,它一直降到“下一次出现”,并且出现“下一个没有出现”的错误。我没看到...是吗?

Option Explicit
Public i As Integer

Sub ReplaceComponent()
Dim NameStr As String
Dim NewNamePath As String

Dim NameStr2 As String
Dim OldNamePath As String

For i = 0 To 99 Step 1

NameStr = Renamer.New_Name.Text               'Concatenates the full new file path
NewNamePath = Renamer.Path_Text.Text & "\" + NameStr & "-" & Right("00" & i, 3) & ".ipt"

NameStr2 = Renamer.Old_Name_Display.Text      'Concatenates the old file NAME
OldNamePath = NameStr2 & "-" & Right("00" & i, 3) & ".ipt"


Dim oOccurrence As ComponentOccurrence               'Creates a ton of errors that have been giving me a headache
For Each oOccurrence In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences
    If oOccurrence.ReferencedDocumentDescriptor.FullDocumentName = OldNamePath Then
    oOccurrence.Replace NewNamePath, True
Exit For
    End If

    If i = 99 Then
DeletetheDirectory                            'When i = 99, deletes the temporary directory
                                              'Will save the file
                                              'Will close the file
Resolve_and_Open.Show vbModal                 'Reopens form 3 to select the next assembly
    Else: Next oOccurrence
    Next i
    End If

End Sub

最佳答案

我认为您的问题很简单,就是您在下一个i之后有End If。如果i = 99,则应首先关闭,并且根本不需要Else,因为无论i = 99与否,都应循环播放。

    If i = 99 Then
        DeletetheDirectory                                          
        Resolve_and_Open.Show vbModal               
    End if
    Next oOccurrence
Next i

关于vba - 下一个没有?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22560689/

相关文章:

c++ - 我的基本 C++ 程序中有一个未指明的错误

java - 使用GCC编译Java文件时出错

java - 尝试创建新对象时出现不兼容类型错误

vba - 由于(可能)数据验证导致 Excel 崩溃

vba - 将 Vookup 与 VBA 中打开的窗口中定义的变量一起使用

vba - 如何在 Outlook 2010 中将嵌入图像添加到 HTML 邮件中

awk - 我的第一个脚本中的语法错误。(最小,最大)

debugging - Chrome : Uncaught SyntaxError: Unexpected end of input

java - 递归排序: quick sort syntax

vba - Excel 中的多个权限层