Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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:

VB
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        
    Else
        'code to handle error and close destination workbook
    End If
     
    If ActiveWorkbook.CanCheckIn = True Then
        ActiveWorkbook.CheckIn
        ActiveWorkbook.Close
        Windows("A").Activate
        MsgBox "The file has been checked in."
    Else
        '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

See here:CanCheckOut method[^]

Example:
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.


VB
Sub UseCanCheckOut(docCheckOut As String)

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


This may help: http://office.microsoft.com/en-001/excel-help/excel-services-i-the-basics-RZ010285479.aspx?section=2[^]

Quote:


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.
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900