powercell99
Board Regular
- Joined
- May 14, 2014
- Messages
- 75
Morning, I need help using VBA to load and install my macro as an AddIn.
I created a macro to autocorrect room number problems that we've been having in excel because of the way excel interprets the room numbers into Scientific Notation and Dates (ei: 9E23 becomes 9E+23 or 900000000000000000000000, and 6-6049 becomes 6/01/6049 or 1515545. so the macro would be handle for other people in the office, so i saved it as an Add-in. But i want to make the installation and Adding of the Add-in as easy as possible for the other users. I came across a code to install & add the add-in using a procedure, but i dont understand where the code should exist and what triggers it. Any help you could provide would be greatly appreciated.
I am including the macro for the roomnumberfix and also the Add-In installation code i found to automate the installation (but cant figure out how to get it to work.
Code that supposedly automates the installation of the AddIn:
Code for the Room Number Fix (this is the code that needs to become the addin):
I created a macro to autocorrect room number problems that we've been having in excel because of the way excel interprets the room numbers into Scientific Notation and Dates (ei: 9E23 becomes 9E+23 or 900000000000000000000000, and 6-6049 becomes 6/01/6049 or 1515545. so the macro would be handle for other people in the office, so i saved it as an Add-in. But i want to make the installation and Adding of the Add-in as easy as possible for the other users. I came across a code to install & add the add-in using a procedure, but i dont understand where the code should exist and what triggers it. Any help you could provide would be greatly appreciated.
I am including the macro for the roomnumberfix and also the Add-In installation code i found to automate the installation (but cant figure out how to get it to work.
Code that supposedly automates the installation of the AddIn:
HTML:
Sub InstallRoomNumFix()
Dim CreateAnAddIn As AddInOn Error GoTo ErrorhandlerSet CreateAnAddIn = AddIns.Add _ (Filename:="MSS_AddIn.xlam") CreateAnAddIn.Installed = True MsgBox CreateAnAddIn.Title & " has been installed" Exit Sub Errorhandler: MsgBox "An error has occured"
End Sub
Code for the Room Number Fix (this is the code that needs to become the addin):
HTML:
Sub FixRmNum()
Application.OnKey "^l", "FixRmNum"
'created August 2014
Dim LR As LongDim rcell As RangeDim rng As Range
Application.DisplayAlerts = FalseApplication.AskToUpdateLinks = False
Set rng = Selection
Selection.NumberFormat = "@"
For Each rcell In rng
If Mid(rcell, 2, 2) = "E+" Then rcell = Left(rcell, 2) & Right(rcell, 2) ElseIf rcell.Value = 100000000 Then rcell.Value = "1E08" ElseIf rcell.Value = 200000000 Then rcell.Value = "2E08" ElseIf rcell.Value = 10000000000# Then rcell.Value = "1E10" ElseIf rcell.Value = 30000000000# Then rcell.Value = "3E10" ElseIf rcell.Value = 50000000000# Then rcell.Value = "5E10" ElseIf rcell.Value = 70000000000# Then rcell.Value = "7E10" ElseIf rcell.Value = 80000000000# Then rcell.Value = "8E10" ElseIf rcell.Value = 90000000000# Then rcell.Value = "9E10" ElseIf rcell.Value = 20000000000000# Then rcell.Value = "2E13" ElseIf rcell.Value = 2000000000000# Then rcell.Value = "2E12" ElseIf rcell.Value = 50000000000000# Then rcell.Value = "5E13" ElseIf rcell.Value = 200000000000000# Then rcell.Value = "2E14" ElseIf rcell.Value = 1000000000000# Then rcell.Value = "1E12" ElseIf rcell.Value = 900000000000000# Then rcell.Value = "9E14" ElseIf rcell.Value = 800000000000000# Then rcell.Value = "8E14" ElseIf rcell.Value = 500000000000000# Then rcell.Value = "5E14" ElseIf rcell.Value = 800000000000000# Then rcell.Value = "8E14" ElseIf rcell.Value = 8000000000000# Then rcell.Value = "8E12" ElseIf rcell.Value = 10000000000000# Then rcell.Value = "1E13" ElseIf rcell.Value = 900000000000# Then rcell.Value = "9E11" ElseIf rcell.Value = 800000000000# Then rcell.Value = "8E11" ElseIf rcell.Value = "195893" Then rcell = "5-2436" ElseIf rcell.Value = "198815" Then rcell = "5-2444" ElseIf rcell.Value = "200276" Then rcell = "5-2448" ElseIf rcell.Value = "201737" Then rcell = "5-2452" ElseIf rcell.Value = "203928" Then rcell = "5-2458" ElseIf rcell.Value = "205389" Then rcell = "5-2462" ElseIf rcell.Value = "207581" Then rcell = "5-2468" ElseIf rcell.Value = "208311" Then rcell = "5-2470" ElseIf rcell.Value = "209042" Then rcell = "5-2472" ElseIf rcell.Value = "211964" Then rcell = "5-2480" ElseIf rcell.Value = "577206" Then rcell = "5-3480" ElseIf rcell.Value = "669278" Then rcell = "6-3732" ElseIf rcell.Value = "675821" Then rcell = "5-3750" ElseIf rcell.Value = "675852" Then rcell = "6-3750" ElseIf rcell.Value = "677313" Then rcell = "6-3754" ElseIf rcell.Value = "697370" Then rcell = "5-3809" ElseIf rcell.Value = "699927" Then rcell = "5-3816" ElseIf rcell.Value = "708693" Then rcell = "5-3840" ElseIf rcell.Value = "717459" Then rcell = "5-3864"
ElseIf rcell.Value = "726225" Then rcell = "5-3888" ElseIf rcell.Value = "742295" Then rcell = "5-3932" ElseIf rcell.Value = "745217" Then rcell = "5-3940" ElseIf rcell.Value = "745947" Then rcell = "5-3942" ElseIf rcell.Value = "748869" Then rcell = "5-3950" ElseIf rcell.Value = "815679" Then rcell = "4-4133" ElseIf rcell.Value = "1330700" Then rcell = "5-5543" ElseIf rcell.Value = "1338005" Then rcell = "5-5563" ElseIf rcell.Value = "1571791" Then rcell = "6-6203" ElseIf rcell.Value = "1572887" Then rcell = "6-6209" Else
End If Next rcell
Range("A1").Select
Application.DisplayAlerts = True
MsgBox "The ""Room-Number-Corrector"" has corrected the Room Numbers for you!", vbInformation End Sub