Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. Sub ButtonClick1()
  2.  
  3. Dim addin As Office.COMAddIn
  4. Dim automationObject As Object
  5. Dim error As String
  6. Dim error1 As String
  7. Dim Result As Boolean
  8. Dim ReportResult As String
  9. Dim LastRowLeft As String
  10. Dim LastRowRight As String
  11. Dim sheetname As String
  12.  
  13. sheetname = ActiveSheet.Name
  14. For Each addin In Application.COMAddIns
  15. If addin.Description = "Enabler4Excel" Then
  16. Set automationObject = addin.Object
  17. End If
  18. Next addin
  19.  
  20. Result = automationObject.LogIn("myemail.org", "mypassword", "https://login.salesforce.com", error)
  21. If Result = False Then
  22. MsgBox error
  23. End
  24. End If
  25.  
  26. ReportResult = automationObject.RunReport("00Od0000004yulX", error1)
  27.  
  28. Dim wb As Excel.Workbook
  29. Set wb = ThisWorkbook
  30. Set ws = wb.Sheets("2016 Incidents Dashboard")
  31.  
  32. With ws.QueryTables.Add(Connection:="TEXT;" & ReportResult, Destination:=ws.Range("A1"))
  33. .TextFileParseType = xlDelimited
  34. .TextFileCommaDelimiter = True
  35. .RefreshStyle = xlOverwriteCells
  36. .Refresh
  37. End With
  38.  
  39. Result1 = automationObject.LogOut()
  40.  
  41. Worksheets("2016 Incidents Dashboard").Activate
  42. LastRowLeft = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
  43. LastRowRight = ws.Range("M" & ws.Rows.Count).End(xlUp).Row
  44. Range("M" & LastRowRight & ":U" & LastRowRight).Select
  45. Selection.AutoFill Destination:=Range("M" & LastRowRight & ":U" & LastRowLeft)
  46.  
  47. ActiveWorkbook.RefreshAll
  48. Worksheets(sheetname).Activate
  49. End Sub
  50.  
  51. Set automationObject = FindEnablerAddin()
  52. ' [...]
  53. Private Function FindEnablerAddin() As Object
  54. For Each addin In Application.COMAddIns
  55. If addin.Description = "Enabler4Excel" Then
  56. Set FindEnablerAddin = addin.Object
  57. Exit Function
  58. End If
  59. Next addin
  60. 'FindEnablerAddin should be Nothing
  61. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement