我有以下代碼...我已經在這裏討論過。它一直在演變,所以現在有點不同了,我想。下一個沒有/沒有下一個錯誤
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