Skip to main content

Salesforce reporting: XL-Connector and VBA

In an earlier post, I mentioned a tool I'm using to import Salesforce data - via SOQL or existing reports - into Excel. This post is more about using that tool, XL-Connector from Xappex. Here, I'll walk through the (simple) process of importing and refreshing a report, and I'll provide a simple VBA macro to automate the refresh. In a future post, I'll expand on that macro to show a friendly view of my opportunity pipeline and a single-page view of how each of my sales reps are doing against a series of KPIs.

XL-Connector loginImporting a report is simple enough. From the XL-Connector tab, select Log In and enter your credentials. I'm using the old id and password (as opposed to SSO), so I provide that along with my 'token'.  (Don't remember your token? Log in to Salesforce via your browser, click on your photo, select Settings, then 'reset my security token'.)

Once you're logged in the lock turns green. Back in Excel, on the XL-Connector tab, select Reports. Because you're logged in with your own Salesforce credentials, the connector will present you with the reports and folders that you have access to in Salesforce. Select the report of interest and click Run Reports. The raw data from your report will be pulled into your Excel file. For me, this is already a win vs my old process of exporting the report details, then switching to Excel and opening the file from my downloads folder.

But the bigger win comes when I start to automate this. Unfortunately, you can't simply use the macro recorder. You can try, but it comes up empty. You can also read Xappex' blog post about using VBA with XL-Connector.

For my purposes, however, I'm only using two of the VBA calls they outline: login and refresh. That leaves me a really simple macro:

Option Explicit
Public automationObject As Object
Dim errorText As String
Dim result As Boolean

Sub SFDCLogin()
    Set automationObject = Application.COMAddIns("TaralexLLC.SalesforceEnabler").Object
    result = automationObject.Login("[UserId]", "[PswdToken]", "https://login.salesforce.com", errorText)
     If result = False Then
       MsgBox errorText
       End
    End If
End Sub

Sub RefreshSheet()
    automationObject.Refresh (False)
End Sub

Sub LoginAndRefresh()
    Call SFDCLogin
    Call RefreshSheet
End Sub

I could save that macro with the Excel file into which I pulled the report. In practice, I have that macro in a file of its own. Then I can easily reuse it, and I only have one file in which to update my password and token. It also allows me to distribute the updated report without setting of security warnings about embedded macros.

Another benefit of using XL-Connector to import and refresh a report is that the data is pulled into Excel as a table. That offers a number of benefits. Two at the top of my list: (1) any formulas I have in adjacent columns automatically get updated, and (2) the table range definition changes to adapt to a changing number of rows in my report; that's especially handy when I use the table data as the source of a pivot table. But that's a future post...





Comments

Popular posts from this blog

Salesforce Pipeline Reporting - part 1 of 3

In a dozen (plus) years working with Salesforce, I've never been entirely happy with the built in reporting of my opportunity pipeline. I can export details, or a printed (formatted) view, but I lose the interactivity. I can use a dashboard, which is better now in Lightning in that I can see a lot more fields in a table component. But flexible views require filtered dashboards, and just maintaining the filter values (if they go down to a rep level) can be onerous. Plus applying (or removing) a filter tests my (very limited) patience. So I've typically exported the report details into Excel, and there created a workbook that includes (1) summary info, (2) scrollable deal lists with hyperlinks back to the opportunity records in Salesforce and (3) filters that let me instantly switch views, say among teams, reps, opportunity types, or fiscal periods. My process around this involved LOTS of VBA and LOTS of formulas. Lately, I've (finally) gotten turned on to slicers in Exc

Using Excel with Salesforce: One tool, two tips

Obviously, Salesforce has strong built-in reporting tools. And I'm a big fan of the dashboards, especially filtered dashboards and dynamic dashboards. WAY better than the old approach of creating a unique set of reports and a corresponding dashboard for every conceivable view. Still, I often want to pull my Salesforce data into Excel. This might be for further manipulation / processing, aggregating data that doesn't live in Salesforce, or distribution to non-Salesforce users (hey, those licenses are expensive!). Reporting Tool - XL-Connector: I'm using a new (to me) tool when I have to repeatedly pull Salesforce data into Excel: XL-Connector  (fka Enabler 4 Excel) from Xappex. There's a lot you can do with XL-Connector. My primary use is just to extract data from Salesforce, and this can be done in two ways: reports or SOQL queries. The great part is that once you've captured data into an Excel file, refreshing the data is trivial. I've stored my credential