2016-11-08 3 views
0

FileName이 이미 있는지 확인하고 싶습니다. 필자가 작성한 것은 로컬 데스크탑에서 테스트 할 때 완벽하게 작동합니다. 그러나 모든 FileNames는 Sharepoint에 저장됩니다. 내가 거기에서 그것을 테스트했을 때, 그것은 효과가 없다! 나는 항상 오류 메시지가 나타납니다 : 불량 파일 이름 또는 번호. 이 내가 쓴 것입니다 : 그것은 작동하지 않는 이유VBA 파워 포인트를 사용하여 파일이 이미 존재하는지 확인

Private Sub CommandButton21_Click() 

Dim NewFileName    As String 
Dim OwnPathName    As String 

oldWeekDay = Weekday(Now) 

Select Case oldWeekDay 

Case 1 
    NewFileName = "PT PM Weekly " & Format(Date + 4, "yyyymmdd") 
Case 2 
    NewFileName = "PT PM Weekly " & Format(Date + 3, "yyyymmdd") 
Case 3 
    NewFileName = "PT PM Weekly " & Format(Date + 2, "yyyymmdd") 
Case 4 
    NewFileName = "PT PM Weekly " & Format(Date + 1, "yyyymmdd") 
Case 5 
    NewFileName = "PT PM Weekly " & Format(Date, "yyyymmdd") 
Case 6 
    NewFileName = "PT PM Weekly " & Format(Date + 6, "yyyymmdd") 
Case 7 
    NewFileName = "PT PM Weekly " & Format(Date + 5, "yyyymmdd") 

End Select 

OwnPathName = ActivePresentation.Path 
FullFileName = OwnPathName & "\" & NewFileName 

'for debug only (can remove it later) 
'MsgBox OwnPathName 
'MsgBox FullFileName 


Dim StrFile    As String 
Dim FileFound   As Boolean 

FileFound = False 
'look for all types of PowerPoint files only (filter only to PowerPoint files to save time) 
StrFile = Dir(OwnPathName & "\*pptm*") 

Do While Len(StrFile) > 0 
If InStr(StrFile, NewFileName) > 0 Then 
    FileFound = True 
    Exit Do 
End If 
StrFile = Dir 
Loop 

If FileFound Then 
MsgBox "Modification already done" 
Else 
RemoveTextboxes 
AllBlackAndDate 
SaveAllPresentations (FullFileName) 
End If 

End Sub 

이해가 안 돼요! 문제 해결을 도와 주시겠습니까? 미리 감사드립니다.

+0

내 OwnpathName = https://sec-ishare.infineon.com/sites/MC_PM/Shared%20Documents/09_Reporting/PT/2016 – Zigouma

답변

0

이 방법이 효과가있을 것이라고 생각합니다. PC 또는 디렉토리에있는 모든 디렉토리를 반복적으로 사용하여 액세스 할 수 있습니다.

F = Dir(StrFile, 7) 'sets f equal to the first file name 
Do While F <> ""  'loops until there are no more files in the directory 

If InStr(StrFile, NewFileName) > 0 Then 
    FileFound = True 
    Exit Do 
End If 

    F = Dir   'set f equal to the next file name in the directory 

Loop