Click here to Skip to main content
11,930,843 members (56,018 online)
Rate this:
Please Sign up or sign in to vote.
See more: MS-Excel SharePoint VBA
Hello everyone. I'm new to this but have searched and plagiarised and cobbled together the following code in order to take some data from an open Excel file and copy it into a Sharepoint-hosted second Excel file. I then want to check out and immediately check in the destination file to save the change:

Workbooks.Open Filename:= _
        "" 'Destination workbook Sharepoint URL
    Worksheets("").Activate 'Destination sheet
'code to prepare print area etc

Windows("A").Activate 'Source workbook
'code to select source data for copying
Windows("B").Activate 'Destination workbook
'code to paste data

If Workbooks.CanCheckOut("") = True Then
        ActiveWorkbook.CheckOut 'to check out destination workbook        
        'code to handle error and close destination workbook
    End If
    If ActiveWorkbook.CanCheckIn = True Then
        MsgBox "The file has been checked in."
        'code to handle error and close destination workbook
    End If

The problem I have is that at the point of checking out the destination workbook file, I get a Windows 'Save As' dialog box inviting me to save the destination file to the Sharepoint library it came from. I was hoping the file would automatically save to my 'Sharepoint Drafts' folder as normal without the need for a dialog box...

Any bright ideas out there?
Posted 13-Jun-12 7:55am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

See here:CanCheckOut method[^]

This example verifies that a workbook is not checked out by another user and can be checked out. If the workbook can be checked out, it copies the workbook to the local computer for editing.

Sub UseCanCheckOut(docCheckOut As String)
    ' Determine if workbook can be checked out.
    If Workbooks.CanCheckOut(Filename:=docCheckOut) = True Then
        Workbooks.CheckOut (Filename:=docCheckOut)
        MsgBox "You are unable to check out this document at this time."
    End If
End Sub

This may help:[^]


Animation description:

In the SharePoint document library, the Web address, or URL of the library to publish to, is visible at the top of the window. The New button is visible, which means that the person who sees the button has the SharePoint permissions to save files to the library.

In Excel, the cursor clicks the Microsoft Office Button Button image, points to Publish, and clicks Excel Services.

In the File Name box, the document library URL is entered (leaving "Forms/AllItems.aspx" off at the end). In the Save as type box, Excel Workbook is selected (there are only two Excel file formats to use when you publish a workbook to Excel Services: Excel Workbook and Excel Binary Workbook). The cursor clicks Save. The document library appears in the Save as window.

A file name is entered, and the cursor clicks Save again to publish the file to the document library.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Thanks ML, but I think the problem may have lain with our Sharepoint set up. In the end I just opted to open the file - the system then checked it out automatically, so problem solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 13 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100