
09-26-2018, 05:23 AM
|
Novice
|
|
Join Date: Sep 2018
Posts: 1
|
|
Editing Word documents through VBA in SharePoint
I have word document with numerous command buttons on (with the VBA code for the click events being referenced in a template).
Each button has a different function but what they all pretty much share is that they will open other documents, edit them and then save/close. This all happens on our corporate network shared storage without any really intervention from the user, apart from clicking on the command button.
We are in the process of moving to a cloud-based SharePoint Solution, which means that the vba code will now have to do the above from documents stored on SharePoint and not from network storage.
I’m very new to SharePoint and I’m trying to adapt the code to work with SharePoint but I’ve hit a few issues that I just can’t seem to resolve/understand.
So far, I have been able to open, edit and save/close a document using the following
Code:
Dim docPath As String
docPath = ActiveDocument.Path & "/workingpaper.docx"
Documents.Open (docPath)
With Documents("workingpaper ").Tables(4)
.Cell(1, 1).Select
Selection.TypeText "test"
End With
Documents("workingpaper ").Close (wdSaveChanges)
The problem is that while the above is running, it is theoretically possible for someone to checkout the same document for editing. Therefore, I thought it would be best to check out the document in SharePoint rather than opening it, however this is where I hit a few problems.
If I use
Code:
Documents.CheckOut docPath
The document flashes up on screen and then disappears. Then, no matter how I try and reference the document I always get a bad file name error, like once it’s checked out it can no longer find it. I certainly can’t see it on screen.
As our current SharePoint solution which I am testing on is 2013 (moving to 2016 in the cloud), I understand that the document is only marked as checked out in SharePoint, rather than a local version being downloaded.
My questions is once I have checked out a document using
Code:
documents.checkout (File path)
how do I reference/call this document so that I can do something with it such as edit the contents, check it back in etc. (the check in function also fails with the bad file name error).
|