VBA and Sharepoint

BSR

New Member
Joined
Mar 26, 2023
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Can anyone assist on VBA and Sharepoint.
I have a table on sharepoint and Excel with Roll no as unique column. Suppose, if a new column (city) is added in Excel file. I need a VBA code which will update city info in sharepoint. Your help will be appreciated. Thanks.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Can anyone assist on VBA and Sharepoint.
I have a table on sharepoint and Excel with Roll no as unique column. Suppose, if a new column (city) is added in Excel file. I need a VBA code which will update city info in sharepoint. Your help will be appreciated. Thanks.
The following VBA macro will update the values of columns based on a unique column (Roll no).
You can replace boilerplate text with necessary information to suit your need.
Set the reference to Microsoft ActiveX Data Objects 6.1 Library before running this macro.
VBA Code:
Public Sub UpdateSharePointList()
    Dim objCnn As ADODB.Connection
    Dim objRs As ADODB.Recordset
    Set objCnn = New ADODB.Connection
    With objCnn
        .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE=<sharepoint site url>;LIST=<ListId>;"
        .Open
    End With
    Set objRs = New ADODB.Recordset
    Dim arrFields(1) As Variant
    arrFields(0) = "Column1"
    arrFields(1) = "Column2"
    Dim arrValues(1) As Variant
    arrValues(0) = "ValueOfColumn1"
    arrValues(1) = "ValueOfColumn2"
    objRs.Open "SELECT * FROM [NameOfList] WHERE [UniqueColumn] = 'Value';", objCnn, adOpenKeyset, adLockOptimistic
    objRs.Update arrFields, arrValues
    If objRs.State = adStateOpen Then objRs.Close
    If objCnn.State = adStateOpen Then objCnn.Close
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,143
Messages
6,123,282
Members
449,094
Latest member
GoToLeep

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top