该文档必须包含内容类型属性-运行时错误-2147216381(80041403) [英] This document must contain content type properties - Run time error - 2147216381(80041403)
问题描述
我使用以下VBA代码将文件保存到SharePoint文件夹(onedrive同步).由于某些我不知道的原因而关闭,因此未显示SharePoint属性
I save my file to the SharePoint folder(onedrive sync) using the following VBA code. Off late for some reasons not known to me the SharePoint properties are not displayed
ActiveWorkbook.SaveAs fileName:=spath & e
其中spath是SharePoint路径,e是文件名.
wherein spath is the SharePoint path and e is the filename.
但是,如果将文件手动保存到同一文件夹,则会显示属性.
However, if a file is saved manually to the same folder then the properties appear.
感谢您的帮助
为了更好地理解,这是我的查询的屏幕截图
For better understanding here is a screenshot of my query
推荐答案
如果无法将文件直接保存到SharePoint,则可以尝试解决方法-将书籍保存在本地磁盘上(例如,在Temp目录中)并沿您已知的路径复制该文件,并将其作为计算机上的磁盘连接.之后,可以删除临时文件(或将其保留一段时间作为安全网),并可以断开磁盘连接.像这样:
If you cannot save the file directly to SharePoint, then you can try a workaround - save the book on a local disk (for example, in the Temp directory) and copy this file along a path known to you, connecting it as a disk on your computer. After that, the temporary file can be deleted (or left for some time as a safety net) and the disk can be disconnected. Something like this:
Sub storeToSharePoint(ByVal sPath As String, sFolderName As String, sFilename As String)
Dim FSO As Object, NW As Object, sTempPath As String, ToPath As String, newFileName As String, sDrive As String
Rem First store ActiveWorkbook to Temp with name sFilename
sTempPath = Environ("Temp")
If Right(sTempPath, 1) <> Application.PathSeparator Then
sTempPath = sTempPath + Application.PathSeparator
End If
ActiveWorkbook.SaveAs Filename:=sTempPath & sFilename
Rem And now - copy to SharePoint:
sDrive = AvailableDriveLetter() ' Try get drive-letter
If sDrive = vbNullString Then
Debug.Print "No free letter to connect network location - file '" _
& sFilename & "' will not be copied"
Else
Set NW = CreateObject("WScript.Network")
Call NW.MapNetworkDrive(sDrive, sPath)
Set FSO = CreateObject("scripting.filesystemobject")
ToPath = sDrive & "\" & sFolderName & "\" & sFilename
FSO.CopyFile Source:=sTempPath & sFilename, Destination:=ToPath
Call NW.RemoveNetworkDrive(sDrive)
Rem If need Kill temp-file
Rem FSO.DeleteFile sTempPath & sFilename
Set FSO = Nothing
Set NW = Nothing
End If
End Sub
这里sPath是您的spath-SharePoint网站的根文件夹;sFolderName-SharePoint中文件夹的路径(您不想将所有文件保存到根文件夹,将它们放得更深一些,对吗?),而sFilename是您的"e".
Here sPath is your spath - root folder of your SharePoint site; sFolderName - path to folder in your SharePoint (You don't want to save all files to the root folder, you put them a little deeper, right?) and sFilename is your "e".
您还需要AvailableDriveLetter函数.它非常简单,它多次发布在Internet上,没有任何变化(Google给出了三十万个链接).我把它放在这里:
You also need the AvailableDriveLetter function. It is very simple, it many times published in the Internet without any unchanges (Google gives out more than three hundred thousand links). I'll put it here:
Function AvailableDriveLetter() As String
Dim i As Integer
AvailableDriveLetter = vbNullString
With CreateObject("Scripting.FileSystemObject")
For i = Asc("D") To Asc("Z")
If Not .DriveExists(Chr(i)) Then
AvailableDriveLetter = Chr(i) & ":"
Exit For
End If
Next
End With
End Function
这篇关于该文档必须包含内容类型属性-运行时错误-2147216381(80041403)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!