krishnaoptif
Board Regular
- Joined
- Sep 17, 2010
- Messages
- 140
I am using below VBA code to add items in SharePoint 2010 and it is working fine.. but now my I am trying to migrate from sharepoint 2010 (All lists) to Office 365 SharePoint... but the same VBA code is not working now for Office 365 sharepoint site. It was giving me some kind of Access denied issue then i also tried to add my user name and password after ( objXMLHTTP.Open "POST", SharePointUrl + "_vti_bin/Lists.asmx", False, "KrishnaK@mySite.onmicrosoft.com", "MyPassword@123") code line but still giving me the access denied issue. Please suggest me that how to do this..
Code:
Const SharePointUrl = "https://mySite.sharepoint.com/"
Const ListNameOrGuid = "{F7191B56-3CC7-42E1-BA59-42291D4E6838}"
Sub Add_ItemInSharePointList(c As MyCls)
'=======================================================================
' Variable ini
'=======================================================================
Dim objXMLHTTP As MSXML2.XMLHTTP
Dim strBatchXml, strBatchXml2 As String
Dim strSoapBody As String
'=======================================================================
' Set obj
'=======================================================================
Set objXMLHTTP = New MSXML2.XMLHTTP
'=======================================================================
' Add a new item
'=======================================================================
strBatchXml = "<Batch OnError='Continue'><Method ID='3' Cmd='New'><Field Name='ID'>New</Field><Field Name='Title'>" + c.C1 + "</Field><Field Name='CustomerName'>" + c.C2 + "</Field></Method></Batch>"
objXMLHTTP.Open "POST", SharePointUrl + "_vti_bin/Lists.asmx", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
objXMLHTTP.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
strSoapBody = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " _
& "xmlns:xsd='http://www.w3.org/2001/XMLSchema' " _
& "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><UpdateListItems " _
& "xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>" & ListNameOrGuid _
& "</listName><updates>" & strBatchXml & "</updates></UpdateListItems></soap:Body></soap:Envelope>"
objXMLHTTP.send strSoapBody
If objXMLHTTP.Status = 200 Then
'Do something with response
MsgBox "Records is added"
End If
Set objXMLHTTP = Nothing
End Sub