Friday, April 15, 2011

Uploading Excel Data into Sharepoint Lists

How to bulk upload and synchronize data into SharePoint using the Excel Add-in and SharePoint Designer Workflows

Overview
Provide the ability for selected individuals who need to continue to maintain data in Excel and also share the data with users via SharePoint taking advantage of all SharePoint’s built-in features for lists.
This solution provides the ability for Excel users to select data stored in their Excel spreadsheet and synchronize the data to a custom SharePoint list eliminating the sometimes redundant and time-consuming process of entering each item individually.
Screenshot from a table in Excel spreadsheet:
TableSyncSharePointContextSmallsyncSharePointContextSmall
This scenario is part of an overall solution that takes advantage of SharePoint’s out-of-the-box features including SharePoint Designer workflows and custom lists to provide an online database for event tracking, a database of subject matter experts, workflow processes for resourcing, and incorporating scoring data imported from pre-populated reports downloaded in Excel format.  
In addition the solution uses the new document sets in SharePoint 2010 to allow user to upload and share supporting files and tag supporting files at a folder level eliminating redundant input.
Configuring SharePoint
  • Create a new custom list to serve as a public list that will display the data to end-users.
  • Create a new custom list to serve as an import list supporting the import workflow process.  This list is created directly from the Excel spreadsheet using the Excel Add-in’s Publish and allow Sync command (more later on this).
  • Create a new site column named BulkImportID and that will be added to both the Import List and Public list.  
  • Create a new SharePoint Designer workflow to handle the import process.  Set the workflow to execute when a new item is added to the Import List. 
  • Add logic to the workflow detect whether a new item should be added or whether the item has been previously added to the public list requiring only an update to the list item.  The purpose of the BulkImportID is to be used to evaluate the workflow condition.
  • Using the create item function in the workflow populate the public list with the appropriate values from each newly added item in the import list and set the BulkImportID for each added list item. Delete each list item in the import list using the Delete Item function when the workflow has succeeded for the item.
Installing and Configuring the Excel Add-in
  • Install the Excel Add-in to the user’s desktop or laptop (individuals contributing data to the system) This provides the mechanism to synchronize the data from the user’s Excel spreadsheet to the Import List in SharePoint.
  • Save the spreadsheet as Excel 2003-2007 format as described in the Excel Add-in configuration instructions.  You can also create a copy of the original to support the import process to maintain the original’s advanced features.   
  • Configure the Excel spreadsheet for the Excel Add-in on the Excel spreadsheet by completing the configuration steps.  Create a new table in Excel with your data and use the Publish and allow sync command to deploy your Import List for the first time.  Optionally add a new worksheet to each spreadsheet where the  user can copy in the specific data they need to import to SharePoint preserving the source worksheets.
Advantages
  • Users can continue to use their Excel spreadsheets for advanced computations, offline access, and custom formatting while also being able to share the data via SharePoint. 
  • Users can bulk-import pre-populated spreadsheets and reports provided by other systems into SharePoint. 
  • Custom filtered views including progressive filtering can be created and shared via SharePoint not provided in Excel auto-filtering. 
  • SharePoint Designer workflows provide a non-code mechanism to both import new items into the Public List and also detecting existing items for performing updates.   
Using the Excel Add-in:
publishAndSyncToolBarSmall
Deploy Excel Add-in to selected users who will be importing data from Excel to SharePoint
Brief Description This add-in works with Excel 2007 to allow you to synchronize data in a table with a list on a SharePoint site.
Download from MSDN http://www.microsoft.com/downloads/details.aspx?FamilyId=25836E52-1892-4E17-AC08-5DF13CFC5295&displaylang=en
Configure Excel spreadsheets for Publishing and Synchronizing Excel 2007 Tables to SharePoint Lists
Summary: In Microsoft Office Excel 2007, the ability to synchronize the data between a table and a list in Microsoft Windows SharePoint Services is deprecated. This article describes an add-in that enables you to update the information in a SharePoint list from Excel 2007.
Configuration Instructionshttp://msdn.microsoft.com/en-us/library/bb462636(office.11).aspx#Office2007SynchronizeSharePointListfromExcel_Synchronizing

Important considerations when using the Excel Add-in.
  • Create your custom “Import List” directly from the Add-in using the Publish and allow sync command in the Table Tools-Design tab of your Excel spreadsheet provided by the Excel Add-in.  You can add your own fields to the Import List later and synchronize with Excel. 
    Think carefully about what fields you want as required fields and the desired order in your spreadsheet before provisioning the Import List since the field order is difficult to re-arrange once the Excel spreadsheet is connected to SharePoint. 
  • Take advantage of the ability for the Excel spreadsheet to incorporate pick-lists from the columns in your SharePoint Import list. 
  • There is a limit of 6 fields if I remember correctly and you are not able to provide for multiple selections but very usefull for maintaining data consistancy and case where selecting users from AD would be usefull.
  • A common confusion I have seen on MSDN for users implementing the add-in is the Publish and allow Sync command in the Excel toolbar.  Some users attempt to select this command to sync the data with SharePoint.  This command is only used to provision the initial list in SharePoint bound to the Excel table and not used for updates.  For updates right-click anywhere on the Excel table and use the additional features added to the context-menu to sync data (see screenshot above)
Conclusion
There are circumstances when users need to continue to use existing Excel spreadsheets and adding each data item to SharePoint individually would be both redundant and time-consuming.  Using the Excel Add-in in combination with custom Import Lists and SharePoint Designer workflows provide one mechanism for bulk-uploading data from Excel to SharePoint. 

Saturday, April 2, 2011

Classes In VBA

Classes In VBA

Class Basics

For illustration, let's adapt the Employee Type described above into a class. First, insert a class module into your VBProject (from the Insert menu in the VBA editor). Name the class CEmployee (it is common practice to use a 'C' as the first letter of a class). There are three properties to create: Name, Address, and Salary. These values will be stored in private variables within the class. Since they are declared Private, they cannot be accessed outside the class module.

Private pName As String
Private pAddress As String
Private pSalary As Double

Next, we need to declare Property procedures to allow these variables to be read from and written to. This is done with Property Get and Property Let functions (or Property Set for object type variables).

''''''''''''''''''''''
' Name property
''''''''''''''''''''''

Public Property Get Name() As String
Name = pName
End Property
Public Property Let Name(Value As String)
pName = Value
End Property

''''''''''''''''''''''
' Address property
''''''''''''''''''''''

Public Property Get Address() As String
Address = pAddress
End Property
Public Property Let Address(Value As String)
pAddress = Value
End Property

''''''''''''''''''''''
' Salary property
''''''''''''''''''''''

Public Property Get Salary() As Double
Salary = pSalary
End Property
Public Property Let Salary(Value As Double)
pSalary = Value
End Property

The Get procedure is used to return a value out of the class, and the Let procedure is to put a value into the class. Note that the return data type of the Get property procedure must be the same data type as the (last) parameter to the Let property procedure. Otherwise, you'll get a compiler error.

Because Property procedures can contain any code you like, the Let Salary procedure can be written to exclude non-positive values.

Public Property Let Salary(Value As Double)
If Value > 0 Then
pSalary = Value
Else
' appropriate error code here
End If
End Property

A property can be made read-only simply by omitting the Let procedure. For example, a read-only property might be withholding tax, which is calculated when it is called. E.g.,

Property Get WithholdingTax() As Double
WithholdingTax = calculated value
End Property

Finally, the class can contain methods, such as a PrintPaycheck procedure.

Public Sub PrintPaycheck()
' actual code to print check
End Sub

Now that we have defined the class, we can create objects based on the class. In a standard code module, declare a variable of type CEmployee.

Dim Emp As CEmployee

Then, Set that variable to a new instance of the class and assign some property values.

Set Emp = New CEmployee
Emp.Name = "Joe Smith"
Emp.Address = "123 Main Street"
Emp.Salary = 40000

Automatically Expand a Named Range in Excel | Excel Semi-Pro

Automatically Expand a Named Range in Excel | Excel Semi-Pro



Inserting a row inside this range will automatically expand the reference for the Named Range, but normally a user would add data to bottom of the table in the first empty row.
My solution is event based. I write a simple subroutine.
Sub ShiftRangeAndRename()
Const n As String = "myFoodData"
Dim rng As Range
Set rng = Range(n).CurrentRegion
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1, rng.Columns.Count)
rng.Name = n
End Sub
Then reference it from the deactivate routine on the MyData worksheet.
Private Sub Worksheet_Deactivate()
Call ShiftRangeAndRename
End Sub
When a user goes to the MyData worksheet and updates data and returns to the main worksheet, the worksheet deactivate routine calls the routine to update the range reference and its associated name. This also works if they are deleting data, but that’s not common in this type of situation.

Related posts:
  1. Put an OFFSET Formula Inside a Named Range
  2. Become the OFFSET Function and Tell a Short Story
  3. Expand Menus in Excel 2003
  4. Name and Select a Range with the Name Box in Excel
  5. The VLOOKUP Function in Excel

Defined names to auto update graphs

How to use defined names to automatically update a chart range in Excel