VBA script to post/update/delete calendar items into sharepoint calendar

promoboy

New Member
Joined
Dec 5, 2010
Messages
8
I am looking for a script to post/update/delete items into a sharepoint calendar.

I found a working script to make new lists on sharepoint but my knowledge of vba is not big enough to work on a solution to let it work on a calender list.

VBA Code:
Public Sub PushSPList()
Dim lname As String, guid As String
Dim arr, arrr
Dim NewList As ListObject
Dim L As ListObjects
' Get the collection of lists for the active sheet
    Set L = ThisWorkbook.ActiveSheet.ListObjects
    ' Add a new list
If MsgBox("Have you selected the new data?", vbYesNo) = vbNo Then
Exit Sub
    Else
        If MsgBox("New?", vbYesNo) = vbYes Then
            lname = InputBox("What is the name of your new list?")
            Set NewList = L.Add(xlSrcRange, Selection, , xlYes, True)
            NewList.Name = lname
            ' Publish it to a SharePoint site
            NewList.Publish Array("https://*****", lname), False
        Else
arr = getSPitems
lname = arr(2)
            guid = arr(1)
            Set NewList = L(1)
Set arrr = Selection
            Call addSPListItem(arrr, lname, guid)
        End If
    End If
    End Sub
    Sub addSPListItem(rar As Variant, lnme, guid)
    Dim arr, lguid As String, spurl As String, lname As String, uitem As Object
    lguid = guid
    lname = lnme
    spurl = "https://******"
    Dim cnt As ADODB.Connection
    Dim rst As ADODB.Recordset 'tb
    Dim mySQL As String
    Set cnt = New ADODB.Connection
    Set rst = New ADODB.Recordset
    mySQL = "SELECT * FROM [" & lname & "];"
    With cnt
.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;" & _
"DATABASE=" & spurl & _
";LIST=" & lguid & ";"
.Open
    End With
    rst.Open mySQL, cnt, adOpenDynamic, adLockOptimistic

Dim fld As Object
Dim arrr()
i = -1
For Each fld In rst.Fields
i = i + 1
ReDim Preserve arrr(0 To i)
    arrr(i) = rst.Fields(i).Name
    Next
    Dim clmns
    clmns = Split(InputBox("Select columns, separated by commas, no spaces after commas...    " & Join(arrr, ", ")), ",")
    Dim Colmns As Object
Set Colmns = CreateObject("Scripting.Dictionary")
For i = 0 To UBound(clmns)
Colmns(i) = clmns(i)
    Next
    jj = 1
Do While rar(jj, 1) ""
rst.AddNew
For kk = 0 To UBound(clmns)
rst.Fields(Colmns(kk)) = rar(jj, kk + 1)
Next
jj = jj + 1
Loop
    rst.Update
    If CBool(rst.State And adStateOpen) = True Then rst.Close
Set rst = Nothing
If CBool(cnt.State And adStateOpen) = True Then cnt.Close
Set cnt = Nothing
MsgBox "Done"
    End Sub

Can this code be updated to use for adding/updating/deleting calender items?
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Watch MrExcel Video

Forum statistics

Threads
1,126,940
Messages
5,621,728
Members
415,853
Latest member
Newlife72

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
Top