• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to call an Add-In using VBA

ThrottleWorks

Excel Ninja
Hi,


I have an excel add in.

I have downloaded this from google & installed in my excel.


I want to run this add in by VBA. At presnt I need to select & run the add in manually.


I need to further processing on the data once this particular add in runs.


So I can not tell user to select the add in & run it.


Can anyone help me in this please.
 
Example code to call Sub from an installed add-in called "Lukes_Tools.xla"

[pre]
Code:
Run "Lukes_Tools.xla!MyMacro"
[/pre]
If your file name has spaces in the name, you may need to include single quotes.

http://www.mrexcel.com/archive/VBA/3338.html
 
Hi Luke Sir, thanks a lot for the help.


hwoever this is giving me bug, Run Time error 1004.

cannot run the macro 'cov-matrix.xlam!var'.


The macro may not be available in this workbook or all macros may be disabled.


I am using following line to run the macro, VAR is the file name


Run "cov-matrix.xlam!VAR"


Could you please help me in this.
 
Is the add-in currently open/installed? If so, you should be able to see it in the VB Project Explorer window. If it isn't open, you'll need to include the entire file path (note that this will cause the workbook to open)
 
This Add In is currently installed.


I am able see this macro in any excel file, if I am not wrong this has been installed as personal macro, pardon me if I am using wrong terminology.


Name of the Add in is "cov-matrix.xlam", and in the excel file we can see


"Covariance Matrix" next to data analysis, if I click it manually this is working.


The main problem is I want to run this by VBA which is I am not able to do.
 
Sir, thanks a lot for the help. I am sorry but I could not understand your question.


I am using folling code even on a new workbook but it is giving me same bug.


Sub RunAdddIn()


Run "cov-matrix.xlam!VAR"


End Sub
 
No worries sachin. It was a long shot, but I was just asking if the macro you are trying to call (in this case, VAR) doesn't need fed arguements. I.e., the called macro doesn't look like

[pre]
Code:
Sub VAR(r as range, x as long) as Boolean
'does stuff
End Sub
If so, we'll need to feed some arguments. Hopefully it's just a simple macro that starts like:

Sub VAR()
'does stuff
End Sub
[/pre]
 
Luke Sir, I think I am giving you some wrong information.


I have a file, file name is "VAR.xlsm".


I have different modules in this file, one module is named "CreateCorrelation".


I want to run this "cov-matrix.xlam" add in in this module.


I tried running this macro in the same module by using line


"Run "cov-matrix.xlam!CreateCorrelation" this gave me bug.


I tried running this macro in a new module using variations like


"Run "cov-matrix.xlam!VAR"


"Run "cov-matrix.xlam"


"Run "cov-matrix"


I think I am making some silly mistake somewhere, thanks a lot for your support & valuable time.


One more thing,


If I do Alt T O, excel options I can see the add in name as

"variance/covariance matrix add-in"


Location of the file is my desktop, add in file name is "cov-matrix.xlam".

Hope this information might help you.
 
file name is "VAR.xlsm"

This part is confusing me a little. Within the add-in, there are 3 things. The name of the add-in, the module name containing the specici sub you want, and the Sub name.

Eg.

My Addin named Lukes_Tools.xla, has a module names "MySubs", and one of those macros is "QuickCalc". If I want to run that macro from another workbook's module, I use the line

[pre]
Code:
Run "Lukes_Tools.xla!QuickCalc"
[/pre]
So, I'm not sure where the "VAR" name is coming from, whether that's the name of the file/macro that you are currently working in, or the one that you are trying to run. If the latter, it shouldn't have any extension at the end though...
 
Sir I am preparing a macro, name of this macro file is "VAR.xlsm”.


I have four different modules in this file. I am processing data in each module.

As I complete processing in 1st module I move on to 2nd module & so on.


In the 4th module I have done some calculations, name of this module is “CreateCorrelation”.

Once some part of the calculations are done I want to run this Add In (“"cov-matrix.xlam”).


After installing the add in the excel.


If I open any excel file I can see VBAProject (cov-matrix.xlam)

There is a Userform named CovDialog.

There is also a module1, this module has enormous code which I don’t understand.


Now the problem is, I want VBA to run this add in, & when the add in gets done I will start further processing.


I really appreciate your patience with me, I know I am giving lots of confusing information, extremely sorry for that.

Usually I try things which I have at least little idea, but this add in thing has thrown me completely off guard.


Have a nice day Sir ! !
 
Sir I will be leaving for the home withing next 10 - 15 minutes.


So if you advised me to do something & I did not respond quickly, please pardon me.


Have a nice weekend.
 
Hi, sachinbizboy!


Does this help?

http://www.mrexcel.com/forum/excel-questions/656737-how-call-add-using-visual-basic-applications.html

http://www.tvmcalcs.com/blog/comments/VarianceCovariance_Matrix_Add-in_for_Excel_2007/

http://books.google.com.ar/books?id=WdeBv_YHW4MC&pg=PT439&lpg=PT439&dq=cov-matrix.xlam&source=bl&ots=IcLedoQ1iS&sig=-4lYRrSD2zWPK6eKyPR2TmO4H1g&hl=es-419#v=onepage&q=cov-matrix.xlam&f=false


Regards!


EDIT: I'm afraid you departure'll be slightly delayed :)
 
I think we're getting closer at least. Within the add-in, you mentioned that there's a userform. Are you wanting this UserForm to be displayed? There's probably some macro within the add-in that initializes/shows the form. The name of that macro is what we need to know. I think there's still some confusion as to the difference between module names and macro names. As long as you don't have two modules with similarly named macros, you shouldn't need to know the module names.


So, within the module1 that you mentioned, we just need to find the name of the macro that you want to run/call.


EDIT: No worries about the delays, have a good weekend. Holiday weekend for me actually, so I won't be back till Tuesday.
 
Sir JB7.


"http://www.tvmcalcs.com/blog/comments/VarianceCovariance_Matrix_Add-in_for_Excel_2007/"


You are correct ! my senior has gave this add in from this link only. But I was aware about the source.


Now after going throught this link, I came to know about the original source.


We took this Add In because, I did not know how to create this table manually.


SirJB7, pardon me but if I am not wrong, I stuck at how run this Add In by VBA.


I did not know anything about "Variance/Covariance Matrix", but I am required to use this in a macro.


Thanks a lot for the help & have a nice day.
 
Luke Sir, you are correct. There is a user form, I want it to get displayed.


Another thing is, the user form will ask for input range, output range.

My boss wants me to input even that range by VBA. But I know this is of the topic.


When I started I thought, 1st I will populate the userform by VBA then will start playing with the code. But I was totally wrong.


Sir I wish you a great weekend !


I will post the code in the next replly, hoep this might make things more clear than my confusing reply.
 
Option Explicit
Option Base 1
'===============================================================================
'Author: Timothy R. Mayes, Ph.D.
'Website: http://www.tvmcalcs.com/blog/
'Version: 1.0
'Date: 2/5/2009
'This code creats a "live" variance/covariance matrix on your worksheet.
'
'It sets up a range with matrix functions linked to your data, so it will
'update automatically if the data changes.
'
'It can create either a normal var/cov matrix, or a probability weighted var/cov matrix.
'
'It can show the entire matrix, hide the upper part, or hide the lower part.
'
'It can create a population or sample var/cov matrix. Note that Excel only does population.
'
'Formulas (using fake named ranges)
'
'If Data are in columns:
'Equal Weighted: =MMULT(TRANSPOSE(Data - Mean), Data - Mean)/VarCount
'Unequal Weighted: =MMULT(TRANSPOSE(Weights*(Data - Mean)), Data - Mean)
'
'If Data are in rows:
'Equal Weighted: =MMULT(Data - Mean, TRANSPOSE(Data - Mean))/VarCount
'Unequal Weighted: =MMULT(Data - Mean, TRANSPOSE(Weights*(Data - Mean)))
'
'Note: Means are calculated within the formulas as a weighted (equal or unequal) average.
'This makes the actual formulas long and ugly, but don't need a separate range for averages.
'
'Planned Updates:
'None at this time
'
'Acknowledgements:
'Thanks to Dave Peterson for helping me to figure out a hack for the 255 character limit in .FormulaArray by using .Replace and a fake string
'His method was posted at http://www.dailydoseofexcel.com/archives/2005/01/10/entering-long-array-formulas-in-vba/
'===============================================================================

'The global ribbon object
Dim grxIRibbonUI As IRibbonUI

Sub rxIRibbonUI_onload(ribbon As IRibbonUI)
'Set up the ribbon variable so that we can add to it
Set grxIRibbonUI = ribbon
End Sub

Sub rxbtn_CovMatrix(control As IRibbonControl)
'Callback for ExcelSim onAction
'Call the CovMatrix() sub to run the add-in code
Dim w As Workbook
Dim Cnt As Integer
Dim FName As Variant
Cnt = 0
'Count how many regular workbooks are open, not counting personal.xls*
For Each w In Application.Workbooks
FName = Split(w.Name, ".")
If (w.IsAddin = False And StrComp(FName(0), "personal", vbTextCompare) <> 0) Then Cnt = Cnt + 1
Next
'If 1 or more regular workbooks, then run the add-in. Otherwise give an error message and exit.
If Cnt > 0 Then
Call CovMatrix
Else
MsgBox "You must have an open workbook to use this add-in", vbOKOnly, "Covariance Matrix Add-in"
Exit Sub
End If
End Sub

Sub CovMatrix()
Dim WeightRng As Range
Dim InputRng As Range
Dim LabelRng As Range
Dim OutputRng As Range
Dim TmpRng As Range
Dim LeftLabels As Range, TopLabels As Range
Dim HasTitle As Byte
Dim HidePartofMatrix As Byte
Dim MeanStr As String
Dim InputSht As String, OutputSht As String, WeightStr As String
Dim NumVars As Integer
Dim i As Integer
Dim LabelArray()
Dim c As Variant
Const FakeStr As String = "X_X_X" 'This is a place holder to make FormulaArray work with formulas > 255 characters, it will be replaced

CovDialog.Show
If CovDialog.CancelPressed Then
Unload CovDialog
Exit Sub
End If
'Get the Data into our range variables
Set InputRng = Range(CovDialog.InputEditBox.Text)
Set OutputRng = Range(CovDialog.OutputEditBox.Text).Cells(1, 1) 'We only want upper-left corner, we will calculate the rest
If CovDialog.WeightsEditBox.Text <> "" Then
Set WeightRng = Range(CovDialog.WeightsEditBox.Text)
Else
Set WeightRng = Nothing
End If

If CovDialog.LabelsBox = True Then 'Set LabelRng and Resize InputRng to remove labels
If CovDialog.ColumnButton = True Then 'Labels in first row
Set LabelRng = Range(InputRng.Cells(1, 1), InputRng.Cells(1, InputRng.Columns.Count))
Set InputRng = Range(InputRng.Cells(2, 1), InputRng.Cells(InputRng.Rows.Count, InputRng.Columns.Count))
NumVars = InputRng.Columns.Count
Else 'Labels in first column
Set LabelRng = Range(InputRng.Cells(1, 1), InputRng.Cells(InputRng.Rows.Count, 1))
Set InputRng = Range(InputRng.Cells(1, 2), InputRng.Cells(InputRng.Rows.Count, InputRng.Columns.Count))
NumVars = InputRng.Rows.Count
End If
Else
'Labels not selected, so no LabelRng
Set LabelRng = Nothing
If CovDialog.ColumnButton = True Then NumVars = InputRng.Columns.Count Else NumVars = InputRng.Rows.Count
End If

If CovDialog.TitleBox = True Then HasTitle = 1 Else HasTitle = 0 '1 if has a title, 0 otherwise

'Get Sheet Names for input data and output data. Note that we are grabbing the first cell in the zero-based array.
InputSht = Split(CovDialog.InputEditBox.Text, "!")(0)
OutputSht = Split(CovDialog.OutputEditBox.Text, "!")(0)
If Not WeightRng Is Nothing Then WeightStr = Split(CovDialog.WeightsEditBox.Text, "!")(0)
'If sheet names are the same, set InputSht to InputRng.Address because we don't need the sheet name.
If StrComp(InputSht, OutputSht, vbTextCompare) = 0 Then
InputSht = InputRng.Address
If Not WeightRng Is Nothing Then WeightStr = WeightRng.Address
Else 'Sheet names are different, add sheet name to addresses if possible
If InStr(CovDialog.InputEditBox.Text, "!") Then InputSht = InputSht + "!" + InputRng.Address Else InputSht = InputRng.Address
If Not WeightRng Is Nothing Then
If InStr(CovDialog.WeightsEditBox.Text, "!") Then WeightStr = WeightStr + "!" + WeightRng.Address Else WeightStr = WeightRng.Address
End If
End If

If CovDialog.AllButton = True Then
HidePartofMatrix = 0 'Show all of matrix
Else
If CovDialog.LowerButton = True Then
HidePartofMatrix = 1 'Show only lower half of matrix
Else
HidePartofMatrix = 2 'Show only upper half of matrix
End If
End If

'Build the string that calculates the mean to simplify the actual formula string
If CovDialog.ColumnButton = True Then 'Variables in Columns
If WeightRng Is Nothing Then
'Equal weighted
MeanStr = "MMULT(TRANSPOSE(N(ISNUMBER(ROW(" + InputSht + ")))/ROWS(" + InputSht + "))," + InputSht + ")"
Else
'Unequal weights
MeanStr = "MMULT(TRANSPOSE(" + WeightStr + ")," + InputSht + ")"
End If
Else 'Variables in Rows
If WeightRng Is Nothing Then
'Equal weighted
MeanStr = "MMULT(" + InputSht + ",TRANSPOSE(N(ISNUMBER(COLUMN(" + InputSht + ")))/COLUMNS(" + InputSht + ")))"
Else
'Unequal weights
MeanStr = "MMULT(" + InputSht + ",TRANSPOSE(" + WeightStr + "))"
End If
End If

'Calculate Output Range and write labels and formulas
ReDim LabelArray(1 To NumVars)
If LabelRng Is Nothing Then 'If labels aren't supplied, give defaults
For i = 1 To NumVars
LabelArray(i) = "Var " + VBA.Format(i, "#")
Next
Else 'Otherwise, place the given labels into LabelArray
i = 0
For Each c In LabelRng
i = i + 1
LabelArray(i) = c.Text
Next
End If

'This section is where we create, format, and write the output

'If output area has data, then clear the range where we will write the results
Set TmpRng = Range(OutputRng.Offset(0, 0), OutputRng.Offset(NumVars + HasTitle, NumVars))
If Application.WorksheetFunction.CountBlank(TmpRng) = TmpRng.Count Then
TmpRng.Clear
Else
i = MsgBox("The output range contains data. Click OK to overwrite.", vbOKCancel)
If i = 2 Then
Exit Sub 'Exit if user doesn't want to overwrite existing data
Else
On Error Resume Next
TmpRng.Clear
If Err.Number <> 0 Then 'Probably can't clear because there is overlap with an array formula
MsgBox "Cannot clear the output range. Try manually clearing it, or change output range. Exiting routine." + VBA.Chr(13) + VBA.Chr(13) + "Error: " + Err.Description, vbOKOnly
Exit Sub
End If
End If
End If

Application.ScreenUpdating = False
Set LeftLabels = Range(OutputRng.Offset(1 + HasTitle, 0), OutputRng.Offset(NumVars + HasTitle, 0))
Set TopLabels = Range(OutputRng.Offset(0 + HasTitle, 1), OutputRng.Offset(0 + HasTitle, NumVars))
LeftLabels.Value = WorksheetFunction.Transpose(LabelArray) 'Write left column labels
TopLabels.Value = LabelArray 'Write top row labels
Set OutputRng = Range(OutputRng.Offset(1 + HasTitle, 1), OutputRng.Offset(NumVars + HasTitle, NumVars))
If WeightRng Is Nothing Then
'Equal weighted covariance
If CovDialog.ColumnButton = True Then 'Variables in columns
If CovDialog.PopButton Then
OutputRng.FormulaArray = "=MMULT(TRANSPOSE(" + InputSht + "-" + FakeStr + "),(" + InputSht + "-" + FakeStr + "))/Rows(" + InputSht + ")"
Else
OutputRng.FormulaArray = "=MMULT(TRANSPOSE(" + InputSht + "-" + FakeStr + "),(" + InputSht + "-" + FakeStr + "))/(Rows(" + InputSht + ")-1)"
End If
Else 'Variables in rows
If CovDialog.PopButton Then
OutputRng.FormulaArray = "=MMULT(" + InputSht + "-" + FakeStr + ",transpose(" + InputSht + "-" + FakeStr + "))/Columns(" + InputSht + ")"
Else
OutputRng.FormulaArray = "=MMULT(" + InputSht + "-" + FakeStr + ",transpose(" + InputSht + "-" + FakeStr + "))/(Columns(" + InputSht + ")-1)"
End If
End If
Else
'Not equal weighted covariance
If CovDialog.ColumnButton = True Then 'Variables in columns
OutputRng.FormulaArray = "=MMULT(TRANSPOSE(" + WeightStr + "*(" + InputSht + "-" + FakeStr + ")),(" + InputSht + "-" + FakeStr + "))"
Else 'Variables in rows
OutputRng.FormulaArray = "=MMULT(" + InputSht + "-" + FakeStr + ",TRANSPOSE(" + WeightStr + "*(" + InputSht + "-" + FakeStr + ")))"
End If
End If
OutputRng.Replace FakeStr, MeanStr 'This replaces the FakeStr that we put in to shorten the formula so that FormulaArray would work

'Format the output
With LeftLabels
.Font.FontStyle = "Bold Italic"
.HorizontalAlignment = xlRight
End With
With TopLabels
.Font.FontStyle = "Bold Italic"
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlThin
.HorizontalAlignment = xlCenter
End With
With TopLabels.Offset(0, -1)
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlThin
End With
If HasTitle = 1 Then 'Add a title, if requested
If WeightRng Is Nothing Then
If CovDialog.PopButton Then
TopLabels.Offset(-1, -1).Cells(1, 1).Value = "Population Variance/Covariance Matrix"
Else
TopLabels.Offset(-1, -1).Cells(1, 1).Value = "Sample Variance/Covariance Matrix"
End If
Else
TopLabels.Offset(-1, -1).Cells(1, 1).Value = "Weighted Variance/Covariance Matrix"
End If
With Range(TopLabels.Offset(-1, -1), TopLabels.Offset(-1, 0))
.Font.FontStyle = "Bold Italic"
.HorizontalAlignment = xlHAlignCenterAcrossSelection
End With
End If
With OutputRng 'Format the numbers and add a border at bottom
.NumberFormat = "0.00000_)"
.Borders(xlEdgeBottom).Weight = xlMedium
End With
OutputRng.Offset(0, -1).Borders(xlEdgeBottom).Weight = xlMedium

If HidePartofMatrix = 1 Then 'Hide upper half of matrix
For i = 1 To NumVars - 1
With Range(OutputRng.Cells(i, 1 + i), OutputRng.Cells(i, NumVars))
.Font.Color = .Interior.Color
End With
Next i
End If
If HidePartofMatrix = 2 Then 'Hide lower half of matrix
For i = 2 To NumVars
With Range(OutputRng.Cells(i, 1), OutputRng.Cells(i, i - 1))
.Font.Color = .Interior.Color
End With
Next i
End If

Application.ScreenUpdating = True
Unload CovDialog
End Sub
 
Assuming this is within an Add-in called "Cov-matrix.xlam", the code to call this specific sub would be:

[pre]
Code:
Application.Run "cov-matrix.xlam!CovMatrix"
[/pre]
Looking back, I see this is somewhat confusing as the sub name and the file name are similar.
 
Hi Luke Sir, (I know you are on a holiday, sorry for the disturbance)


This is working, thanks a lot.


I tried following line.


Application.Run "CovMatrix"


This is working now, once again thanks to Luke Sir, SirJB7, & Chandoo forum.


Have a nice day to all.
 
dragging the past dragged over. jordans for sale. net/spaceMonday or starting a early wash graduated and went straight to a certain hospital php? title=User:33799177449#homeip_If_I_persist Henceforth will I recognize that each day I am tested by life in like manner.,http://kurohime.homeip.net/kuro/archives/2012/04/post-2329.php#comments,chaussures de foot
to me everything patience; eat com/dealornodeal-new/2006/03/i-thought-the-people-who-come-on-the-show-were-the-ones-who-were-a-few-fries-short-of-a-happy-meal. gaming.asp? the treatment results are clearly visible in recent years only classic to service generations of people title=User:Eibaeccgf#exposure_after_the http://pjjd.the unnatural deaths of everyone are considered to be a bear in the matter ralph lauren. jordans shoes but I decided to love you,http://sqbbs.ccn360.com/viewthread.php?tid=155249&pid=185418&page=1&extra=page%3D1#pid185418,hollister, but the interpretation of the latter than the former has been The N4W China essay But this the Wulanchabu official response to the strange phenomenon of the taking of the 16 who took the test,sac lancel pas cher, can you let your heart Do not upsetphp?Shizhao away tears At the moment,air jordan pas cher,Abercrombieralph laurenair jordansAbercrombieralph laurenralph lauren EFE7alluminati on the community some to fame unscrupulous of people turned up their nosesCheap AbercrombieAbercrombie OutletAbercrombie Outletmichael kors handbags still your beatingBEthis is also a pole spear but I've always believed a feeling that if you do not like why the reluctanceCheap Abercrombie 86air jordans Xu Tong Tong to give up the idea was rejected by memichael kors outletmichael kors handbagslouboutinsE6ne gradually used to it around your daylouboutinsjohnbourne If I persist the promise to each other while China is 645 yuan in the world countdown sixteenthcom/w/indexgottajoinA5 I will succeedAbercrombie Outlet she take her own Looking newbornRelated articles: http://wwwpaldoorg/wiki/User:38642497132#E698_higher_educatio http://imdiycn/20060113/desktop-software-xdeskshow/#comments http://blogarvixecom/how-to-check-whether-the-cpanel-ports-are-open/ Henceforth will I recognize that each day I am tested by life in like manner If I persist if I continue to try if I continue to charge forward I will succeed when the meteor across the sky when the rainbow cross-linked head when the two old people cuddling remember that I have said for some timemichael kors handbagsCheap Abercrombie.
if I continue to try,maillot de foot,http://www.taogure.com/forum.php?mod=viewthread&tid=68704&pid=82679&page=1&extra=page=1#pid82679,9F http://armory.php/User:09864272694#lightly_but_it_is_c http://jimblackler. as a public instinctively avoiding disadvantageslife is also committed major sins of the nation after his death but also indicates that only under the two of us.the wtd China essay China essays in XxP Food and Drug malignant event in China intensified great single spark can start a prairie firethe greater the gap between the Therefore you know it only a bitter Green he is a silent peopleralph lauren outlet the masses of the people and government relationslouboutins Engelhard thinking of their own care is love for youmichael kors outlet Easy come she has a crush the family was forced to accept foreign media interview villagers a banner abusive Zhenping County these promises csq China essays network csq China essay csq China essay one: price pressure and the ban drink the Maotai one: restless hand the most ancient timemichael kors handbags faint thinking about last night and felt refreshed teapotralph lauren Perhaps you do not know what I'm waiting for you come left oneair jordans or some mutual participation through rehearsals Shi by vigorous thanksgiving ceremony people carries the dream of the relentless pursuit of beauty Kaifeng City Tongxu County died pork to the market caused by the attention of the relevant departments asked Professor Qian century still ear maneuverRelated articles: http://wiki2pilschcom/gastronomy/indexphptitle=User:41698820306#he_is_just_exactly http://mandurainmotioncom/profilephpuser=hatsatdq&v=comments http://webgaochengcom/forum/bbs/viewthreadphptid=1411244&pid=1946139&page=1&extra=page=1#pid1946139 Henceforth will I recognize that each day I am tested by life in like manner If I persist if I continue to try if I continue to charge forward I will succeedtitle=User:62299215469#. php/User:91610375811#title. My monthly exam rankings politics a zero by the first straight-line decline to twenty-four. I will succeed. two copies of Western-style steak jordans for sale,sac longchamp,The magistrate of the municipal government to face the hundreds of children of a minor pulled the Grand Place and how?
jordans for sale. But I often think. seems to have a lot of people have existed deep in my memory .B4 but these will not become a purchase contract in black and whitejordans for salephp? 9VZ China essay network the year Xiangla Xie popular Shanghai is the occasion.
 
Back
Top