Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default CheckOut/CheckIn from/to SharePoint 2010

Has anyone else come across this and know of a fix?

Here's the CheckOut code, as it comes from Excel 2010 Help...

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

....For me this 'almost' works. As the requested file opens I get the
Enable Macros prompt, I click Enable and then I see the workbook open
briefly and immediately close.

The only way I've had any degree of success is to use the Open method
aswell...

Sub UseCheckOut(docCheckOut As String)

' Determine if workbook can be checked out.
If Workbooks.CanCheckOut(docCheckOut) = True Then
Workbooks.CheckOut docCheckOut
Workbooks.Open docCheckOut
Else
MsgBox "Unable to check out this document at this time."
End If

End Sub

However, there are a couple of problems with this. Firstly, I get the
Enable macros prompt twice - I don't want users to see that. Secondly,
I want the file to check itself back in when the Before_Close event
fires. If the file closes immediately after being checked out it will
obviously check itself back in. When the code then opens the workbook
with the Open method the file is in the wrong state according to
SharePoint.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default CheckOut/CheckIn from/to SharePoint 2010

Is there anything in the code that would cause the workbook to close on
some conditional criteria?

<FYIThe only way to lose the macro security (& associated warnings) is
to use an automated instance of Excel.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default CheckOut/CheckIn from/to SharePoint 2010

Ah! I just needed to think a bit more logically.

I managed to solve the problem simply by swapping the .CheckOut
and .Open lines like so...

Sub UseCheckOut(docCheckOut As String)


' Determine if workbook can be checked out.
If Workbooks.CanCheckOut(docCheckOut) = True Then
Workbooks.Open docCheckOut
Workbooks.CheckOut docCheckOut
Else
MsgBox "Unable to check out this document at this time."
End If


End Sub


Maybe I didn't look hard enough but I haven't seen this documented
anywhere. But plenty of comments saying "you can't do it from VBA"
followed by mind boggling workarounds using .Net code.

Anyway I hope this helps someone else.

Btw, Something else I found useful - the docCheckOut string is the
FullName of the file you want to open. To get an example of what it
should look like, Open a workbook in your SharePoint Library, Open the
VBE and in the Immediate Window type ?ThisWorkbook.FullName and hit
return. Copying the path from your browser window won't work.

When you check the file back in you can use ThisWorkbook.CheckIn or,
if closing remotely, Workbooks(docCheckIn).CheckIn where docCheckIn is
a string containing the filename only, without the path.

Br, Nick.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default CheckOut/CheckIn from/to SharePoint 2010

Thanks for your response Garry.

I've managed to solve the problem by swapping the methods (see my
reply to myself). However I did try using an automated instance of
Excel but although it passed the CanCheckOut test the code then failed
at the CheckOut method with an error saying the workbook couldn't be
Checked out. Hmmm, that was before I swapped the .Open and .CheckOut
methods though - maybe I should try it again. One less click for the
user if I can get it to work.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default CheckOut/CheckIn from/to SharePoint 2010

Yes, this works...

Private mXlApp As Excel.Application

Sub SPCheckOut(docCheckOut As String)
Set mXlApp = CreateObject("Excel.Application")
' Determine if workbook can be checked out.
If mXlApp.Workbooks.CanCheckOut(docCheckOut) = True Then
mXlApp.Workbooks.Open Filename:=docCheckOut
mXlApp.Workbooks.CheckOut docCheckOut
mXlApp.Visible = True
Else
MsgBox "Unable to check out this document at this time."
End If
End Sub

Sub SPCheckIn(docCheckIn As String)
' Determine if workbook can be checked in.
If mXlApp.Workbooks(docCheckIn).CanCheckIn = True Then
mXlApp.Workbooks(docCheckIn).CheckIn
Else
MsgBox "This file cannot be checked in at this time. Please
try again later."
End If
End Sub

Obvioulsy mXlApp should be disposed of properly elsewhere when
finished with.

Br, Nick.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default CheckOut/CheckIn from/to SharePoint 2010

Nick H submitted this idea :
Yes, this works...

Private mXlApp As Excel.Application

Sub SPCheckOut(docCheckOut As String)
Set mXlApp = CreateObject("Excel.Application")
' Determine if workbook can be checked out.
If mXlApp.Workbooks.CanCheckOut(docCheckOut) = True Then
mXlApp.Workbooks.Open Filename:=docCheckOut
mXlApp.Workbooks.CheckOut docCheckOut
mXlApp.Visible = True
Else
MsgBox "Unable to check out this document at this time."
End If
End Sub

Sub SPCheckIn(docCheckIn As String)
' Determine if workbook can be checked in.
If mXlApp.Workbooks(docCheckIn).CanCheckIn = True Then
mXlApp.Workbooks(docCheckIn).CheckIn
Else
MsgBox "This file cannot be checked in at this time. Please
try again later."
End If
End Sub

Obvioulsy mXlApp should be disposed of properly elsewhere when
finished with.

Br, Nick.


mXlApp will be implicitly destroyed when the file containing the code
that created it terminates. However, it would be best to explicitly
destroy it BEFORE the file closes because anything we leave to VBA to
do implicitly requires extra processing on VBA's part. IMO, it's just
good programming practice to explicitly destroy objects we create when
we no longer need them.

Example:
Set mXlApp = Nothing

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default CheckOut/CheckIn from/to SharePoint 2010

Hello,
Check below link for SharePoint 2010 Introduction to Publishing

https://www.youtube.com/watch?v=aDl8...uxL 2dUaELxAy

Thanks
NSA




On Thursday, December 22, 2011 at 9:46:46 AM UTC-5, Nick H wrote:
Has anyone else come across this and know of a fix?

Here's the CheckOut code, as it comes from Excel 2010 Help...

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

...For me this 'almost' works. As the requested file opens I get the
Enable Macros prompt, I click Enable and then I see the workbook open
briefly and immediately close.

The only way I've had any degree of success is to use the Open method
aswell...

Sub UseCheckOut(docCheckOut As String)

' Determine if workbook can be checked out.
If Workbooks.CanCheckOut(docCheckOut) = True Then
Workbooks.CheckOut docCheckOut
Workbooks.Open docCheckOut
Else
MsgBox "Unable to check out this document at this time."
End If

End Sub

However, there are a couple of problems with this. Firstly, I get the
Enable macros prompt twice - I don't want users to see that. Secondly,
I want the file to check itself back in when the Before_Close event
fires. If the file closes immediately after being checked out it will
obviously check itself back in. When the code then opens the workbook
with the Open method the file is in the wrong state according to
SharePoint.


Hello,
Check below link for SharePoint 2010 Introduction to Publishing

https://www.youtube.com/watch?v=aDl8...uxL 2dUaELxAy

Thanks
NSA
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mark if checkin date is within 30 days of checkout date where name isthe same. steve1040 Excel Programming 4 July 13th 10 07:41 AM
How to CheckIn a checked out file in VBA? Revolvr Excel Programming 0 August 12th 09 08:12 PM
Method 'CheckIn' of object '_workbook' failed Bill Schanks Excel Programming 1 May 9th 06 10:04 PM
Checkin into SPS prompts no matter what... Lasse Bjerre Knudsen Excel Programming 0 June 29th 04 08:46 AM


All times are GMT +1. The time now is 08:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"