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