0

我正在尝试编写一个 vbscript 以便能够签出存储在 sharepoint 服务器上的 excel 文件。

目前我可以从 SharePoint 2010 中检出文件:Link to open Excel file in edit-mode mode

但是,我正在尝试重新签入文件但无法签入。我已经搜索并尝试了每个http://msdn.microsoft.com/en-us/library/office/ff194456%28v=office.14%29.aspx的结帐功能,但不能。

目前我拥有的代码是

Sub CheckInFile

    Dim ExcelApp, ExcelSheet, ExcelBook
    Dim myURL

    myURL = "http://server/Site/excel.xlsx"

    Set ExcelApp = CreateObject("Excel.Application")                        

    If (ExcelApp.WorkBooks.CanCheckIn(myURL) = True) Then
        msgbox ("here")
        ExcelApp.WorkBooks.Open (myURL)
        ExcelApp.Application.WorkBooks.CheckIn myURL

        ExcelApp.ActiveWorkbook.Close
        ' Quit Excel.
        ExcelApp.Quit
        ' Clean Up
        Set ExcelApp= Nothing
    End If

End Sub

然而,脚本在 if 语句处停止并失败,而不是执行。是否有类似的 vbscript 函数来签入文件?

4

3 回答 3

1

我为此苦苦挣扎,并花了很多时间寻找在我的特定环境中有效的解决方案。以下是我需要满足的标准:

  • 使用 vbscript 文件从我的计算机执行该过程
  • 遍历约 200 个 Excel 电子表格的列表
  • 检查每个文件
  • 进行各种条件更新并保存
  • 更新完成后再次签入文件。

以下是未来任何人的替代解决方案,像我一样,尝试了建议的方法,但没有奏效。这是经过测试和工作的:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application") 

objExcel.Visible = True
objExcel.DisplayAlerts = False

Dim MyVar ' so popup alerts narrate the process
          ' and help explain what is happening
          ' for those who want to see it step
          ' by step
Dim docPath
docPath = "\\your server\sites\Docs\sharepoint spreadsheet.xlsx"
' I believe this can be any document path

Set objWorkbook = objExcel.Workbooks.Open(docPath)

cco = objExcel.Workbooks.CanCheckOut(docPath)

MyVar = MsgBox ("can check out? " & cco, 0) 
' -----------------------------------------------------
' this shows "False" every time. I still do not know how 
' to get this to work, but thought it would be valuable
' to include for explanation
' -----------------------------------------------------

objExcel.Workbooks.CheckOut(docPath)
' -----------------------------------------------------
' this SUCCEEDS every time...as long as you have
' the ability to check out the document manually
' -----------------------------------------------------

MyVar = MsgBox ("Update cell", 0)
With objExcel.ActiveWorkbook.Worksheets(1)
    objExcel.Cells( 1, 1 ).Value = "test value"
End With

MyVar = MsgBox ("Save the file", 0)
objWorkbook.Save

MyVar = MsgBox ("check in the file", 0)

objWorkbook.CheckIn
' -----------------------------------------------------
' This actually checks in the active document and *closes 
' it* You don't have to have a separate command to close
' the file, e.g.
'   objWorkbook.Close 
' THIS WILL FAIL.
' -----------------------------------------------------

Set objWorkbook = Nothing
于 2017-11-01T16:23:59.817 回答
0

只需将以下行更改为您的代码:

ExcelApp.Visible = True
ExcelApp.DisplayAlerts = False

谢谢!

 Dim oExcel
 Dim strFileName
 Set oExcel = CreateObject("Excel.Application")
 oExcel.Visible = True
 oExcel.DisplayAlerts = False
 strFileName = "view_2019.xlsm"

'Checkin
 If oExcel.Workbooks(strFileName).CanCheckIn = True Then
   oExcel.Workbooks(strFileName).CheckIn SaveChanges=True,Comments="Updated"
   MsgBox strFileName  & " has been checked in."
 Else
   MsgBox "This file cannot be checked in at this time. Please try again later."
 End If
 set oExcel = nothing
于 2019-04-08T05:45:28.057 回答
0

试试这个:

Dim ExcelApp, ExcelSheet, ExcelBook
    Dim myURL = "http://server/Site/excel.xlsx"
    Set ExcelApp = CreateObject("Excel.Application")                        
    ExcelApp.WorkBooks.Open (myURL)
    If (ExcelApp.ActiveWorkbook.CanCheckIn = True) Then
        ExcelApp.Application.WorkBooks(myURL).CheckIn 
        ExcelApp.ActiveWorkbook.Close
        ' Quit Excel.
        ExcelApp.Quit
        ' Clean Up
        Set ExcelApp= Nothing
    End If
于 2016-11-25T12:24:31.120 回答