SharePoint - Update SharePoint Document Property from Excel VBA

AID: 3663
  • Status: Published

5470 points

  • Bychapmanjw
  • TypeTutorial
  • Posted on2010-09-07 at 15:42:35
Awards
  • Community Pick
The Scenario: Let’s say you have a quote worksheet in Excel that you use to work up sales figures and such for your clients. You utilize SharePoint to manage and keep track of these documents. You would like values from your worksheet to populate SharePoint properties in the document library. For instance, you would like the Quote Date and Quote Amounts to populate in the SharePoint properties for the document.

Out-of-the-box there isn’t a simple way to make this happen. You can view and edit the Document Properties from SharePoint in Excel, but there isn’t a straightforward method of setting those properties from values within your Worksheets. We can, however, accomplish this by using a very simple VBA (Visual Basic for Applications) script.

If you are reading this tutorial, I assume that you are using SharePoint 2007 or SharePoint 2010 with Excel 2007 or Excel 2010 and have a basic understanding of working with both document libraries in SharePoint and with Excel spreadsheets. I will include some links to other tutorials if you are unsure how to complete certain steps.

Here’s how to add the VBA script to accomplish this:

1
In SharePoint, create a new Document Library. (For help: http://www.hosting.com/support/sharepoint3/createdoclib)



2
Add a new Column to the Document Library called “Quote Amount” and set the column type to Currency. (For help: http://office.microsoft.com/en-us/windows-sharepoint-services-help/add-edit-or-delete-a-column-HA001161199.aspx)



3
Copy the URL to the document library from your address bar. (For example, if your URL is http://site/library/forms/allitems.aspx, select http://site/library/ only, the forms/allitems.aspx is the view you are looking at).



4
Open Microsoft Excel and create a new Excel 2007/2010 workbook



5
Save the Workbook as a Macro Enabled Workbook to your document library



a. Go to the Office Button > Save As or File > Save As
b. Paste the URL of the document library into the File Name box and hit enter
c. Once you have browsed to your document library, give your document a name and change the type to Excel Macro-Enabled Workbook

6
Change the value of Cell A7 to 125.99. Change the cell type to Accounting (the dollar symbol on the Home ribbon in the Number section)



7
Select the Developer ribbon tab (if you need to enable the Developer tab, see http://office.microsoft.com/en-us/excel-help/show-the-developer-tab-or-run-in-developer-mode-HA010173052.aspx)



8
Select the Document Panel button to show the SharePoint Document Properties for the document. This is where you could manually edit the properties if you wished.



9
Select Insert > ActiveX Button



10
Your mouse will be turned into crosshairs indicating you can draw a button. Somewhere on the document click and drag to create your button.



11
Right-click your new button and select Properties



12
Set the (Name) to “UpdateButton” and the Caption to “Update SharePoint Properties”



13
Close the Properties window



14
Double-click the button



15
Microsoft Visual Basic for Applications will pop up with the blank function for the UpdateButton loaded



Private Sub UpdateButton_Click()


End Sub
                                    
1:
2:
3:
4:

Select allOpen in new window



16
In the function (after the Private Sub line) add:



For Each Prop In ThisWorkbook.ContentTypeProperties
If Prop.Name = “Quote Amount” Then
Prop.Value = Cells(7, 1).Value
End If
Next Prop
                                    
1:
2:
3:
4:
5:

Select allOpen in new window



17
This function looks for the Prop object in each of the current workbook’s ContentTypeProperties. If it finds the property matching the specified name (“Quote Amount”) is sets its value to our Cell A1. When addressing cells in VBA, it looks first for the row (7) and then for the numeric column (1 instead of A).



18
You can add more properties if you wish. For example, if we had two:



For Each Prop In ThisWorkbook.ContentTypeProperties
If Prop.Name = “Quote Amount” Then
Prop.Value = Cells(7, 1).Value
End If
If Prop.Name = “Quote Date” Then
Prop.Value = Cells(8, 1).Value
End If
Next Prop
                                    
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window



19
Close the Microsoft Visual Basic for Applications window



20
Save your document



21
Every time you click the button you created, the SharePoint Document Properties will be updated on the Document Properties Panel and updated in SharePoint when you save the document.



And there you have it.  By using this method, you can create Excel documents that can update their SharePoint document properties programmatically.

Original Article: http://www.johnchapman.name/sharepoint-2007-%E2%80%93-update-sharepoint-document-property-from-excel-vba/
Asked On
2010-09-07 at 15:42:35ID3663
Tags

SharePoint 2007

,

SharePoint 2010

,

Document Properties

,

Excel

,

VBA

Topic

MS SharePoint

Views
3730

Comments

Expert Comment

by: ericpete on 2010-09-13 at 09:19:26ID: 19356

Congratulations, chapmanjw!

Your article has been published, and it designated as a Community Pick. We hope to see more articles from you.

Thanks,

ericpete
Page Editor

Expert Comment

by: pperisic on 2010-12-23 at 22:17:46ID: 22401

Awesome

Expert Comment

by: sullisnyc44 on 2011-03-17 at 10:52:35ID: 24799

awesome!

What if I wanted to populate an excel worksheet cell (which is an excel template / content type for Purchase Orders) with the Purchase Order number associated with the item via an SPD Workflow?



Expert Comment

by: sullisnyc44 on 2011-04-27 at 12:46:51ID: 26092

what if I want the url of the document library? how do I grab that??

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top MS SharePoint Experts

  1. ACH1LLES

    358,298

    Wizard

    0 points yesterday

    Profile
    Rank: Genius
  2. JamieMcAllister

    189,161

    Guru

    0 points yesterday

    Profile
    Rank: Sage
  3. teylyn

    170,328

    Guru

    900 points yesterday

    Profile
    Rank: Genius
  4. ivan_vagunin

    156,400

    Guru

    0 points yesterday

    Profile
    Rank: Sage
  5. QPR

    123,685

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  6. Tehzar

    100,639

    Master

    0 points yesterday

    Profile
    Rank: Guru
  7. svetaye

    75,681

    Master

    0 points yesterday

    Profile
    Rank: Guru
  8. tedbilly

    71,150

    Master

    0 points yesterday

    Profile
    Rank: Genius
  9. quihong

    52,832

    Master

    0 points yesterday

    Profile
    Rank: Sage
  10. dp_expert

    49,160

    0 points yesterday

    Profile
    Rank: Wizard
  11. colly92002

    41,560

    0 points yesterday

    Profile
    Rank: Master
  12. clayfox

    39,400

    0 points yesterday

    Profile
    Rank: Genius
  13. milindsaraswala

    36,835

    0 points yesterday

    Profile
  14. RainerJ

    31,840

    1,000 points yesterday

    Profile
    Rank: Master
  15. abhitrig

    31,218

    0 points yesterday

    Profile
    Rank: Wizard
  16. dhawalseth

    30,268

    0 points yesterday

    Profile
  17. ImaCircularSaw

    29,438

    0 points yesterday

    Profile
    Rank: Guru
  18. martusha

    25,478

    0 points yesterday

    Profile
  19. zephyr_hex

    21,624

    0 points yesterday

    Profile
    Rank: Genius
  20. FastFngrz

    21,414

    0 points yesterday

    Profile
    Rank: Guru
  21. livanescu

    20,100

    0 points yesterday

    Profile
  22. danshady

    18,870

    0 points yesterday

    Profile
  23. CloudedTurtle

    18,050

    0 points yesterday

    Profile
    Rank: Master
  24. jessc7

    17,102

    0 points yesterday

    Profile
    Rank: Sage
  25. JoeKlimis

    16,318

    0 points yesterday

    Profile
    Rank: Master

Hall Of Fame