【发布时间】:2021-09-24 03:09:51
【问题描述】:
我有如下代码。它正在复制工作表并将其另存为同一文件夹中的新工作簿,并打开活动工作簿。对话框打开,用户为此新工作簿键入新名称。但是,自从公司将文件夹移至 onedrive 后,它不再起作用了。
NewName = InputBox("Please Specify the name of your new workbook", "New Copy")
ActiveWorkbook.SaveCopyAs ThisWorkbook.Path & "\" & NewName & ".xlsx"
ActiveWorkbook.Close SaveChanges:=False
我有全名功能也可以将文件格式更改为 pdf 并且它正在工作。
sPath = ActiveWorkbook.FullName
FileName = LocalFullName(ActiveWorkbook.FullName)
ActiveWorkbook.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:=Left(FileName, InStr(FileName, ".") - 1), _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Private Function LocalFullName$(ByVal fullPath$)
Dim ii&
Dim iPos&
Dim oneDrivePath$
Dim endFilePath$
If Left(fullPath, 8) = "https://" Then
If InStr(1, fullPath, "my.sharepoint.com") <> 0 Then
iPos = InStr(1, fullPath, "/Documents") + Len("/Documents")
endFilePath = Mid(fullPath, iPos)
Else
iPos = 8
For ii = 1 To 2
iPos = InStr(iPos + 1, fullPath, "/")
Next ii
endFilePath = Mid(fullPath, iPos)
End If
endFilePath = Replace(endFilePath, "/", Application.PathSeparator)
For ii = 1 To 3
oneDrivePath = Environ(Choose(ii, "OneDriveCommercial", "OneDriveConsumer", "OneDrive"))
If 0 < Len(oneDrivePath) Then
LocalFullName = oneDrivePath & endFilePath
Exit Function
End If
Next ii
LocalFullName = vbNullString
Else
LocalFullName = fullPath
End If
End Function
我无法在无效代码中应用全名。
【问题讨论】: