I have a sharepoint site which I use vba to upload new data. I have created a Excel Addin which we will deploy to other users so that anybody can upload.
The Excel Addin consists of two modules. The first module is the "functions" module and the second is the code which runs when the button is pushed on the Addin. If I test all this with a normal Excel Macro workbook, it works perfect. However when I test it in the Addin feature, the "Call SaveChanges" part does not work.
Does anybody have any idea what is causing this part to not work? I have even tried adding another button on the Addin for the SaveChanges part but still not working as a Addin.
The SaveChanges Sub it is calling is what saves the data back to sharepoint.
Module 1
Option Explicit
Sub link_edit_Mode()
Dim mySh As Worksheet
Dim spSite As String
Set mySh = Sheets("Sheet1")
Dim src(0 To 1) As Variant
spSite = "https://share.websitehere.com/sites/sitename/" 'site name
src(0) = spSite & "/_vti_bin"
src(1) = "{00000000-8F5B-4736-B48F-337D350E18C1}" 'GUID
mySh.ListObjects.Add xlSrcExternal, src, True, xlYes, mySh.Range("A1")
End Sub
Sub SaveChanges()
Dim mySh As Worksheet
Dim lstOBJ As ListObject
On Error GoTo errhdnler
Set mySh = Sheets("Sheet1")
Set lstOBJ = mySh.ListObjects(1)
lstOBJ.UpdateChanges xlListConflictDialog
Set mySh = Nothing
Set lstOBJ = Nothing
Exit Sub
errhdnler:
Debug.Print Err.Description & Err.Number
End Sub
Sub refresh_Con()
Dim mySh As Worksheet
Dim lstOBJ As ListObject
On Error GoTo errhdnler
Set mySh = Sheets("Sheet1")
Set lstOBJ = mySh.ListObjects(1)
lstOBJ.Refresh
Set mySh = Nothing
Set lstOBJ = Nothing
Exit Sub
errhdnler:
Debug.Print Err.Description & Err.Number
End Sub
Module 2
Sub FollowUps(control As IRibbonControl)
'
Dim lCopyLastRow As Long
Dim lDestLastRow As Long
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Rows("1:5").Select
Range("A5").Activate
Selection.Delete Shift:=xlUp
Columns("H:H").EntireColumn.AutoFit
Columns("I:I").EntireColumn.AutoFit
Sheets.Add.Name = "Sheet1"
' Worksheets("Sheet1").Visible = True
Call link_edit_Mode
Do While (Selection.Offset(1, 0) <> "")
Range("A3").Select
Selection.ListObject.ListRows(1).Delete
Selection.Offset(1, 0).Select
Range("A2").Select
Loop
'Set variables for copy and destination sheets
Set wsCopy = Workbooks("SA_Follow_Ups.xlsx").Worksheets("Follow Ups OpenUnresolved Over")
Set wsDest = Workbooks("SA_Follow_Ups.xlsx").Worksheets("Sheet1")
'1. Find last used row in the copy range based on data in column A
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
'2. Find first blank row in the destination range based on data in column A
'Offset property moves down 1 row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(0).Row
'3. Copy & Paste Data
wsCopy.Range("A2:I" & lCopyLastRow).copy
wsDest.Range("B" & lDestLastRow).PasteSpecial xlValues
Call SaveChanges
ActiveWindow.SelectedSheets.Visible = False
End Sub
So I figured it out.
Sub SaveChanges()
Dim mySh As Worksheet
Dim objListObj As ListObject
On Error GoTo errhdnler
Set mySh = ActiveWorkbook.Worksheets("Sheet1")
Set objListObj = mySh.ListObjects("Table1")
objListObj.UpdateChanges xlListConflictDialog
Set mySh = Nothing
Set objListObj = Nothing
Exit Sub
errhdnler:
Debug.Print Err.Description & Err.Number
End Sub