我正在编写一个脚本,我希望将HTML文档写入sharepoint的字符串。
Dim Content As String
Dim strShare As String: strShare = "\\link\to\share.html"
Dim iFile As Integer: iFile = FreeFile
Open strShare For Input As #iFile
Content = Input(LOF(iFile), iFile)
Close #iFile
但是,每次我在启动时第一次运行脚本时,我都会发现“路径/文件访问错误”。在我第一次访问IE中的“\ link \ to \ share.html”后,路径开始在VBA脚本中解析。
我唯一的想法是IE正在执行某种VBA无法做到的“DNS缓存”。目前我的解决方法是捕获错误并强制在第一次运行脚本时在IE中打开URL。之后,该共享下的每个其他HTML文件都可以正常加载。
作为测试,我尝试在我理解的http://格式化(正斜杠)和WebDAV格式化(\\格式化)之间切换,只有反斜杠分隔的路径才能工作。我也尝试将这个共享解析为IP并以这种方式尝试,但这从未奏效。
我最后的想法是尝试将共享映射到驱动器号名称,然后使用G:\ link \到\ mapped \ share.html专门访问共享。但我不认为这是一个优雅的解决方案,并想知道它是否会以任何方式收到相同的错误。
对于WebDAV,Windows文件处理和VBA文件输入,是否有一些我不明白的事情?通过解析共享域,引发了一些奇怪的事情,我似乎无法调试它。
答案 0 :(得分:0)
看看这是否有助here以及我使用过的示例。
2件事情:我只使用了Sharepoint上的Excel文件,我已经登录了。
Dim oFSO As Object
'Dim oFolder As Object 'if needed
'Dim oFile As Object 'if needed
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("\\sharepoint.site.com@SSL\DavWWWRoot\sites\")
'For Each oFolder In oFolder.SubFolders 'loops through folders
' For Each oFile In oFolder.Files 'loops through files
' 'do stuff
' Next oFile
'Next oFolder
答案 1 :(得分:0)
我对你想做什么感到有点困惑。您想检查SP中的文件并将文件检入SP吗?
Sub testing()
Dim docCheckOut As String
'docCheckOut = "//office.bt.com/sites/Training/Design Admin/Training Plan/adamsmacro.xlsm"
docCheckOut = "http://your_path_here/ExcelList.xlsb"
Call UseCheckOut(docCheckOut)
End Sub
Sub UseCheckOut(docCheckOut As String)
' Determine if workbook can be checked out.
If Workbooks.CanCheckOut(docCheckOut) = True Then
Workbooks.CheckOut docCheckOut
Else
MsgBox "Unable to check out this document at this time."
End If
End Sub
或者......您要列出SP文件夹中的文件吗?
Sub ListFiles()
Dim folder As Variant
Dim f As File
Dim fs As New FileSystemObject
Dim RowCtr As Integer
Dim FPath As String
Dim wb As Workbook
RowCtr = 1
FPath = "http://excel-pc:43231/Shared Documents"
For Each f In FPath
'Set folder = fs.GetFolder("C:\Users\Excel\Desktop\Ryan_Folder")
'For Each f In folder.Files
Cells(RowCtr, 1).Value = f.Name
RowCtr = RowCtr + 1
Next f
End Sub
Sub test()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Users\Excel\Desktop\Ryan_Folder")
'Set colSubfolders = objFolder.SubFolders
'For Each objSubfolder In colSubfolders
Cells(RowCtr, 1).Value = f.Name
RowCtr = RowCtr + 1
'Next
End Sub