将简单的宏另存为SharePoint的基本excel文件,然后执行其他操作。当用户可以访问指定的文件夹FLUX PL时,该宏可以正常工作。
ActiveWorkbook.SaveAs Filename:="https://xxxxcorp.sharepoint.com/sites/CEEControlling/Shared%20Documents/Reporting/FLUX%20Analysis/FLUX%20PL/FLUX%20analysis%20PL%20" & Date & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
如果用户无权访问(因此他看不到文件),则该文件将保存为原始文件的一半,因此它已损坏,因此我必须使用以前的版本。
我尝试了包含代码来检查我是否可以访问/该文件夹存在于SharePoint中,但是它为我提供了
运行时错误'52':文件名或数字错误。
mypath = "https://xxxxcorp.sharepoint.com/sites/CEEControlling/Shared%20Documents/Reporting/FLUX%20Analysis/FLUX%20PL"
mypath = Replace(Replace(mypath, "https:", ""), "/", "\")
mypath = Replace(mypath, Split(mypath, "\")(2), Split(mypath, "\")(2) & "@SSL")
If Dir(mypath, vbDirectory) = "" Then
MsgBox ("Doesnt exist!")
Else:
MsgBox ("Exists!")
End If
我也考虑过On Error Goto [label]
,但是到给我错误时,该文件已被重命名(原始文件已损坏)。
我将不胜感激。
答案 0 :(得分:1)
如果将来有人需要它,我就可以使用。我尝试保存它,如果出现错误,我使用On Error GoTo
并打开“另存为”对话框。
On Error GoTo savior
ActiveWorkbook.SaveAs Filename:= "https://xxxxcorp.sharepoint.com/sites/CEEControlling/Shared%20Documents/Reporting/FLUX%20Analysis/FLUX%20" & Range("H2").Value & "/FLUX%20analysis%20" & Range("H2").Value & "%20" & Date & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = False
On Error Goto 0
GoTo rest
savior:
MsgBox ("You do NOT have access to the default folder on Teams:" & vbNewLine & "Controlling CEE >> Reporting >> Files >> FLUX Analysis >> FLUX " & Range("H2").Value & vbNewLine & vbNewLine & "Select different location for the new trimmed file!")
Filename = "FLUX analysis " & Range("H2") & " " & Date
varResult = Application.GetSaveAsFilename(FileFilter:= _
"Excel Files (*.xlsx), *.xlsx", Title:="Select File Location", _
InitialFileName:=Filename)
If varResult <> False Then
ActiveWorkbook.SaveAs Filename:=varResult, _
FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = False
End If
On Error Goto 0
GoTo rest
rest: