Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Mark if checkin date is within 30 days of checkout date where name isthe same. | Excel Programming | |||
How to CheckIn a checked out file in VBA? | Excel Programming | |||
Method 'CheckIn' of object '_workbook' failed | Excel Programming | |||
Checkin into SPS prompts no matter what... | Excel Programming |