我需要检查Sharepoint上是否存在文件。如果没有,我想保存它:如果已经存在,我想保存它的副本
Sub save()
Dim newFile as string, fName as string, path as string
fName = Sheets(“Universe”).Cells(2,2).Value
newFile = fName & Format$(Date, “dd-mm-yyyy”)
path = “SharePoint URL”
If Len(Dir(path & newFile & “.xlsm”) = 0 Then
ActiveWprkbook.SaveAs Filename := path & newFile & “.xlsm”,
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:= False
Else
ActiveWprkbook.SaveAs Filename := path & newFile & “Copy” & “.xlsm”,
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:= False
End If
End sub
第一次成功保存文件;但是,它始终会找到If条件为true并继续覆盖现有文件。
如何更改代码,使其能够识别何时创建了文件并因此复制了文件?
答案 0 :(得分:0)
也许试试看:
路径示例:“ CompletableFuture
为public static CompletableFuture<Void> allOf(CompletableFuture<?>... cfs) {
return andTree(cfs, 0, cfs.length - 1);
}
/** Recursively constructs a tree of completions. */
static CompletableFuture<Void> andTree(CompletableFuture<?>[] cfs, int lo, int hi) {
CompletableFuture<Void> d = new CompletableFuture<Void>();
if (lo > hi) // empty
d.result = NIL;
else {
CompletableFuture<?> a, b;
int mid = (lo + hi) >>> 1;
if ((a = (lo == mid ? cfs[lo] :
andTree(cfs, lo, mid))) == null ||
(b = (lo == hi ? a : (hi == mid+1) ? cfs[hi] :
andTree(cfs, mid+1, hi))) == null)
throw new NullPointerException();
if (!d.biRelay(a, b)) {
BiRelay<?,?> c = new BiRelay<>(d, a, b);
a.bipush(b, c);
c.tryFire(SYNC);
}
}
return d;
}
/** Pushes completion to this and b unless both done. */
final void bipush(CompletableFuture<?> b, BiCompletion<?,?,?> c) {
if (c != null) {
Object r;
while ((r = result) == null && !tryPushStack(c))
lazySetNext(c, null); // clear on failure
if (b != null && b != this && b.result == null) {
Completion q = (r != null) ? c : new CoCompletion(c);
while (b.result == null && !b.tryPushStack(q))
lazySetNext(q, null); // clear on failure
}
}
}
final CompletableFuture<V> tryFire(int mode) {
CompletableFuture<V> d;
CompletableFuture<T> a;
CompletableFuture<U> b;
if ((d = dep) == null ||
!d.orApply(a = src, b = snd, fn, mode > 0 ? null : this))
return null;
dep = null; src = null; snd = null; fn = null;
return d.postFire(a, b, mode);
}
Z:Documents\Reports\2013\"
注意:
"\\sharepoint\Documents\Reports\2013\"
结尾 Sub save()
Dim newFile As String, fName As String, path As String
fName = Sheets(“Universe”).Cells(2, 2).Value
newFile = fName & Format$(Date, “dd - mm - yyyy”)
path = “SharePoint URL”
myWorkbookBasePath = path & newFile & “.xlsm”
If Dir(myWorkbookBasePath, vbDirectory) = "" Then
ActiveWorkbook.SaveAs Filename:=myWorkbookBasePath, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Else:
ActiveWorkbook.SaveAs Filename:=myWorkbookBasePath, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End If
End Sub
应该是\