×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

excel vba check out and check in excel document

excel vba check out and check in excel document

excel vba check out and check in excel document

(OP)
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 "https://site.com/J/TestingFile.xlsx"
Set wbTarget = Workbooks.Open("c:\theTestFile.xlsx")
wbTarget.SaveAs FileName:="https://site.com/J/TestingFile.xlsx"
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?

RE: excel vba check out and check in excel document

Revise your code to the following:

CODE -->

Workbooks.CheckOut "https://site.com/J/TestingFile.xlsx"
 Set wbTarget = Workbooks.Open("c:\theTestFile.xlsx")
 wbTarget.SaveAs FileName:="https://site.com/J/TestingFile.xlsx"
 wbTarget.CheckIn SaveChanges:=False, Comments:="updating file" 
 wbTarget.Close False 

RE: excel vba check out and check in excel document

(OP)
nope the error still appears

RE: excel vba check out and check in excel document

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"

RE: excel vba check out and check in excel document

(OP)
I'm wandering if my sharepoint have some issues.

RE: excel vba check out and check in excel document

(OP)
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.

RE: excel vba check out and check in excel document

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.

RE: excel vba check out and check in excel document

(OP)
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.

RE: excel vba check out and check in excel document

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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources