18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating Custom Excel Add-Ins 45<br />

Private Sub OKButton_Click()<br />

CaseChangerDialog.Hide<br />

Application.ScreenUpdating = False<br />

‘ Upper case<br />

If OptionUpper Then<br />

For Each cell In Selection<br />

If Not cell.HasFormula Then<br />

cell.Value = StrConv(cell.Value, vbUpperCase)<br />

End If<br />

Next cell<br />

End If<br />

‘ Lower case<br />

If OptionLower Then<br />

For Each cell In Selection<br />

If Not cell.HasFormula Then<br />

cell.Value = StrConv(cell.Value, vbLowerCase)<br />

End If<br />

Next cell<br />

End If<br />

‘ Proper case<br />

If OptionProper Then<br />

For Each cell In Selection<br />

If Not cell.HasFormula Then<br />

cell.Value = StrConv(cell.Value, vbProperCase)<br />

End If<br />

Next cell<br />

End If<br />

Unload UserForm1<br />

End Sub<br />

The following procedure is executed if the user clicks the Cancel button.<br />

Private Sub CancelButton_Click()<br />

Unload UserForm1<br />

End Sub<br />

Testing the workbook<br />

Before you convert this workbook to an add-in, it’s a good idea to test it. You should test it when a different<br />

workbook is active in order to simulate what happens when the workbook is an add-in. Remember that an<br />

add-in is never the active workbook, and it never displays any of its worksheets.<br />

To test it, I saved the workbook, closed it, and then reopened it. With the workbook open, I then activated<br />

a different workbook, selected some cells that contained text and then pressed Alt+F8 to display the Macros<br />

dialog box. I executed the ShowUserForm macro and tried all of the options.<br />

777

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!