我有以下代码...我已经在这里讨论过。它一直在演变,所以现在有点不同了,我想。下一个没有/没有下一个错误
Option Explicit
Public i As Integer
Public oOccurrence As ComponentOccurrence
Public Sub ReplaceComponent()
Dim NameStr As String
Dim NewNamePath As String
Dim NameStr2 As String
Dim OldNamePath As String
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"
'Creates a ton of errors that have been giving me a headache
Dim oOcc As ComponentOccurrence
For Each oOcc In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences
If oOcc.ReferencedDocumentDescriptor.FullDocumentName = OldNamePath Then
Set oOccurrence = oOcc
End If
Do While i < 99
oOcc.Replace NewNamePath, True
If i = 99 Then
DeletetheDirectory
'Will close the file
Resolve_and_Open.Show vbModal 'Reopens form 3 to select the next assembly
Else:
For i = 1 To 99 Step 1
Next
End If
Loop
End Sub
所以现在我在“End Sub”行上得到“For Without Without”错误。如果我在下一个地方添加,则会收到“Next Without For”错误。我想这与我的“如果...然后”的陈述有关,但我不完全确定。
任何想法?
编辑1:
这里是DeletetheDirectory模块。我没有问题。我用它在我的形式,以及:
Option Explicit
' Delete this directory and all the files it contains.
Sub DeletetheDirectory()
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.deletefolder "C:\\InventorTempFolder"
On Error Resume Next
End Sub
而且Resolve_and_Open是一个形式,我也没有任何问题:
Private Sub Cancel_Click()
Unload Me 'Triggers cancel button
DeletetheDirectory
End Sub
Private Sub Open_Button_Click()
ThisApplication.SilentOperation = True 'Suppresses the resolve links dialog
Dim myPath As String
myPath = FileName.Text 'Gets the string, FileName, from module 1
Dim Shell As Object
Set Shell = CreateObject("Shell.Application")
Shell.Open (myPath) 'Opens selected file
Resolve_and_Open.Hide 'Hides module
ReplaceComponent
'ReplaceComponent will go here once it works
End Sub
Private Sub OpenAssemblies_Click()
SelectFileOpenDialog 'Calls to OpenFileDialog Module
End Sub
外部For没有下一个,所以你应该只需要把它放在End Sub之前。 什么是:在Else声明之后?这只是一个错字吗? – DoctorMick
它会自动将其更改为实际值。不知道为什么。当我把它放在结束sub之前,我得到一个无效的下一个控制变量引用错误 – meer2kat
你应该删除结尾的冒号。 VBA会认为这是一个标签。 – DeanOC