我创建了一个自动将当前工作簿上传到共享点并触发宏的宏。 宏成功,将文件上传到映射到驱动器的共享点文件夹。
但是,如果SharePoint文件夹是以前创建的方式,宏只能成功。 例如。 也许1天先进。
如果文件夹是新创建的,则无法上传到该文件夹,因为Sorry there's no such folder 。
如果我去窗口资源管理器上的驱动器,我将能够看到新创建的文件夹。 我也尝试复制信息框中显示的文件路径并键入窗口资源管理器,它指示我没有问题的文件夹。
有没有一种方法可以加速流程,为什么会发生这种情况?
宏IF语句
If Dir(spPath) = "" Then MsgBox "Sorry there's no such folder. Folder Path: " & vbNewLine & vbNewLine & spPath & "" Call UnMapDrive(drive) Exit Sub ElseIf Not Dir(spPath & fileName) = "" Then MsgBox("File Already Exist!!!") ElseIf Dir(spPath & fileName) = "" Then FolderCreate (path) ThisWorkbook.SaveCopyAs copyPath & fileName Call FileCopy(path & fileName, spPath & fileName) MsgBox "File Successfully uploaded to SharePoint." Kill (path) & "*.*" RmDir path Call UnMapDrive(drive) End IfI had create a macro that auto upload the current workbook to sharepoint apon triggering the macro. The macro was successful, uploading the file to sharepoint folder that was mapped to the drive.
However, the macro only success if the SharePoint folder is created way before time. Eg. maybe 1 day in advanced.
If the folder is newly created, it would not be able to upload to the folder as Sorry there's no such folder.
If I go to the drive on window explorer, I would be able to see the newly created folder. I also tried copy the file path shown on the msg box and type in window explorer, it directs me to the folder with no issues.
Is there a way I can speed up the process and why does this happens?
Macro IF statement
If Dir(spPath) = "" Then MsgBox "Sorry there's no such folder. Folder Path: " & vbNewLine & vbNewLine & spPath & "" Call UnMapDrive(drive) Exit Sub ElseIf Not Dir(spPath & fileName) = "" Then MsgBox("File Already Exist!!!") ElseIf Dir(spPath & fileName) = "" Then FolderCreate (path) ThisWorkbook.SaveCopyAs copyPath & fileName Call FileCopy(path & fileName, spPath & fileName) MsgBox "File Successfully uploaded to SharePoint." Kill (path) & "*.*" RmDir path Call UnMapDrive(drive) End If最满意答案
更改
If Dir(spPath) = "" Then至
If Dir(spPath, vbDirectory) = "" Then在有人将文件放入目录之前(可能是创建目录后的第二天),您的代码在那里看不到任何文件(因为没有任何文件)。 通过添加vbDirectory它会查找目录本身。
Change
If Dir(spPath) = "" Thento
If Dir(spPath, vbDirectory) = "" ThenUntil someone puts a file into the directory (perhaps a day after the directory is created), your code is not seeing any files there (because there aren't any). By adding vbDirectory it will look for the directory itself.
更多推荐
发布评论