Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ExcelSharepointVBA
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        
    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 13-Jun-12 6:55am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.

 
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.
  Permalink  
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 668
1 OriginalGriff 396
2 Tadit Dash 345
3 sanket saxena 329
4 Peter Leow 203
0 Sergey Alexandrovich Kryukov 12,109
1 OriginalGriff 7,326
2 Peter Leow 5,013
3 Abhinav S 4,013
4 Maciej Los 3,575


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