How to close an xlam

jcarlosd

New Member
Joined
Oct 20, 2002
Messages
40
I have a mymacros.xlam file that opens automatically when called from file mybook.xlsx, with a ribbon and functions for that specific workbook.
From another VBA code, I close mybook.xlsx, and I want to close also mymacros.xlam.

I read on this thread that it is as simple as running
VBA Code:
Workbooks("mymacros.xlam").Close SaveChanges:=False

However, it does not (always) work, because mymacros.xlam is not in the Workbooks collection. Sometimes it correctly close the macro file, sometimes it closes my current workbook, sometimes it crashes.

I tried also to write a macro in mymacros.xlam that closes itself, but again, sometimes it works, sometimes it does not.

I am very confused about this behavior. I googled for a way to close and xlam file but I did not find a solution.

Does anybody have experience with this practice?

J. Carlos
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
There are different ways to load an AddIn into Excel's memory space, so there are also different ways to unload an AddIn.
The code below should fix your issue.

VBA Code:
Sub UnLoadAddin()

    Const cAddIn As String = "AddInName.xlam"          ' <<< change file name to suit

    Dim oAI As Object

    For Each oAI In Application.AddIns
        If StrComp(cAddIn, oAI.Name, vbTextCompare) = 0 Then
            oAI.Installed = False
            Exit Sub
        End If
    Next oAI
    For Each oAI In Application.UsedObjects
        If TypeOf oAI Is Workbook Then
            If StrComp(cAddIn, oAI.Name, vbTextCompare) = 0 Then
                oAI.Saved = True
                oAI.Close
                Exit For
            End If
        End If
    Next oAI
End Sub
 
Upvote 0
How about
VBA Code:
Sub DisableAddin()
  AddIns("mymacros").Installed = False
End Sub
 
Upvote 0
Solution
@Fluff, whenever a loaded xlam is not located in the default AddIn folder (C:\Users\GWteB\AppData\Roaming\Microsoft\AddIns) or not loaded using Excel's UI (Developer tab > AddIns > browse button) your suggestion will fail.
 
Upvote 0
Wasn't aware of that, thanks.
I've always kept add-ins in the default folder.
 
Upvote 0
I also do that at home, at the office that is not possible in my situation. Also not necessary, especially if several users (without knowing it themselves) use the same AddIn.
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,560
Latest member
Torchwood72

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top