Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel vba check out and check in excel document

Status
Not open for further replies.

yuechu

Chemical
Oct 21, 2015
5
I am writing a macro that would:
check out a document from sharepoint
open a document on C drive
save (stack) the open document on the sharepoint document
close the file
check in the document.

my code is as follows:
Workbooks.CheckOut "Set wbTarget = Workbooks.Open("c:\theTestFile.xlsx")
wbTarget.SaveAs FileName:="wbTarget.CheckIn SaveChanges:=False, Comments:="updating file"
wbTarget.Close False

I keep getting an error when I check get to the checkin line:"we can't do that for you because the file is no longer checked out or has been deleted.".....but file is not deleted and I'm checking it in after it was checked out....any ideas?
 
Replies continue below

Recommended for you

Revise your code to the following:
Code:
Workbooks.CheckOut "[URL unfurl="true"]https://site.com/J/TestingFile.xlsx"[/URL]
 Set wbTarget = Workbooks.Open("c:\theTestFile.xlsx")
 wbTarget.SaveAs FileName:="[URL unfurl="true"]https://site.com/J/TestingFile.xlsx"[/URL]
 wbTarget.CheckIn [s]SaveChanges:=False,[/s] Comments:="updating file" 
 [s]wbTarget.Close False[/s]
 
I created a macro in Excel using the above code with the corrections and it worked. The only problem I had is that I needed to have a file on the C: drive first before the code would work. Your check in line should look like the following (no commas): wbtarget.CheckIn Comments:="updating file"
 
I'm wandering if my sharepoint have some issues.
 
when you close the file, it would ask you to check it in again and then you would have to put in a comment and then the error comes up.
 
I had the macro in a different excel file than the one being opened from the SharePoint site. Therefore, when it has the wbTarget.SaveAs command, it is closing the file & automatically checking it in. Additionally, it is showing the comment in the Version History of the document. Try using the code in a different workbook than the ones listed in the macro.
 
It turns out that because our sharepoint requires each person to fill out a number of required file properties before checking it in, it would give me an error when I tried to check it in without assigning them. Now I just need to figure out how to get the macro to fill out some of these required fields so I can check the file in without getting an error.
 
Good Luck, it seems like you're on the right track. You might need to use the With/End With commands to get all of the fields changed when you're checking in the file. You'll probably need to check in with your SharePoint contact to find out the field names (hopefully they'll be more useful than the "normal" IT staff [banghead])
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor