Run an Add-in from another workbook

TheCman81

Well-known Member
Joined
Feb 28, 2012
Messages
535
Hi All,

Thanks in advance.

Excel 2007

I'm looking for a macro to run the same Add-In on various different workbooks. Add-In name is "HRwsBTH"

I have about 20+ workbooks that I need to open and manually refresh my Add-In and it's very time consuming.

So what I would like to achieve with the macro is the following:

1. Open a file
2. Run the Add-In
3. Save the file
4. Close the workbook

I need these steps repeated for each workbook

Thanks

Colin
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
Hello Colin

What is your code to do it on 1 workbook?
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
What macro do you execute in the addin?
Did you use the macro recorder to explore some generated code?
 

TheCman81

Well-known Member
Joined
Feb 28, 2012
Messages
535
There's isn't a macro to run the add-in, the add-in has a built in refresh button that you select
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
In that case, you could try to see what macro is behind the refresh button.
Or is it merely a recalculation that is triggered?
 

TheCman81

Well-known Member
Joined
Feb 28, 2012
Messages
535
The actual code behind the add-in is password protect so can't view it but I've just been told this bit of code can activate the refresh part of the add-inn


<code>Run ("</code>HRwsBTH<code>.xla!Refresh"), True</code></pre>
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
In that case, loop over the files (Dir function) and execute that line of code:

Code:
Sub GetFilesInLoop()

Dim FileName As String


'Edit this declaration to your folder name
FilePath = "C:\myfiles"


FileName = Dir(FilePath & "\*.xls")


Do While FileName <> vbNullString


    With Workbooks.Open(FilePath & "\" & FileName)
        Run "HRwsBTH.xla!Refresh"
        .Save
        .Saved = True
        .Close 0
    End With
    FileName = Dir()
Loop


End Sub
 

TheCman81

Well-known Member
Joined
Feb 28, 2012
Messages
535
Would I be right in thinking since I have 20+ workbooks the code would look like this:

Code:
Sub GetFilesInLoop()

Dim FileName As String


'Edit this declaration to your folder name
FilePath = "C:\myfiles"


FileName = Dir(FilePath & "\Workbook1.xls")
FileName = Dir(FilePath & "\Workbook2.xls")
FileName = Dir(FilePath & "\Workbook3.xls")
FileName = Dir(FilePath & "\Workbook4.xls")

'and so on....


Do While FileName <> vbNullString


    With Workbooks.Open(FilePath & "\" & FileName)
        Run "HRwsBTH.xla!Refresh"
        .Save
        .Saved = True
        .Close 0
    End With
    FileName = Dir()
Loop


End Sub
 
Last edited:

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
No, that is not right. The Dir() function and the Do While Loop take care of searching the files.
Within that loop, each file is opened and the one statement you already had, is executed.
You have to provide the folder name, not all individual file names.
 

Forum statistics

Threads
1,081,518
Messages
5,359,237
Members
400,523
Latest member
ExcelNewbie98

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top