루프와 시트의 논리를 이해하려고 노력했습니다. 나는 .pdf 파일을 폴더에서 다른 것으로 옮기려고 노력하고 있는데, 이는 어떤 기준이 엑셀 파일에 있는지 아니면 H = YES 열에 있는지에 따라 달라집니다. 나는 코드의 맨 아래에 구문 오류가 내려컴파일 오류/구문 오류를 어떻게 수정합니까?
**objFSO.CopyFile Source:=OldPath & Range("H"&CStr(iRow)).Value & sFileType,
Destination:=NewPath**
Sub Rectangle1_Click()
Dim iRow As Integer
Dim OldPath As String
Dim NewPath As String
Dim sFileType As String
Dim bContinue As Boolean
bContinue = True
iRow = 2
' The Source And Destination Folder With Path
OldPath = "C:\Users\bucklej\Desktop\Spec\"
NewPath = "C:\Users\bucklej\Desktop\Dest\"
sFileType = ".pdf"
'Loop Through Column "H" To Pick The Files
While bContinue
If Len(Range("H" & CStr(iRow)).Value) = Yes Then
MsgBox "Files Copied"
bContinue = False
Else
Range("H" & CStr(iRow)).Value = "No"
Range("H" & CStr(iRow)).Font.Bold = False
If Trim(NewPath) <> "" Then
Set objFSO = CreateObject("scripting.filesystemobject")
'Check if destination folder exsists
If objFSO.FolderExists(NewPath) = False Then
MsgBox NewPath & "Does Not Exist"
Exit Sub
End If
'Using CopyFile Method to copy the files
Set objFSO = CreateObject("scripting.filesystemobject")
objFSO.CopyFile Source:=OldPath & Range("H"&CStr(iRow)).Value & sFileType,
Destination:=NewPath
End If
End If
End If
iRow = iRow + 1
Wend
End Sub
올바른 코드 아래 :
Sub Rectangle1_Click()
Dim OldPath As String, NewPath As String
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
'~~> File location bucklej
OldPath = "C:\Users\bucklej\Desktop\Specs\"
NewPath = "C:\Users\bucklej\Desktop\Dest\"
Set ws = ThisWorkbook.Sheets("Specification Listing")
Range("A2").Activate '<--- to make sure we're starting at the right spot
For i = 2 To 1000
If Cells(i, 8).Value = "YES" Then '<--- correct, 8th column over
On Error GoTo ErrHandle
fso.CopyFile OldPath & Cells(i, 1).Value & ".pdf", NewPath
End If
Next i
ErrHandle:
ws.Cells(i, 11).Value = "File Not Found"
Resume Next
End Sub
당신은 정말 원래의 질문으로 돌아가 대신 세 개의 게시물 작성이 현재의 코드 하나를 편집해야 던져. 저스틴. – mrbungle
당신은 너무 많은 'end if'를 가지고 있고 오류가있는 행과 그 아래에있는 행은 모두 한 행에 있어야합니다. – mrbungle
여분의 End If를 삭제하고 위의 행에 "Destination : = NewPath"를 추가하고 여전히 오류가 발생합니다. –