0

I have an xlam code that I wish to have a "desktop shortcut" to.
So I managed to find a code that could open a new workbook and some code that should run a VBA code but it does not work for me.

This is the code:

Option Explicit

On Error Resume Next

ExcelMacroExample

Sub ExcelMacroExample() 

  Dim objExcel 

  Set objExcel = CreateObject("Excel.Application")
  objExcel.Visible = True

  Set objWb = objExcel.Workbooks.Add ' it seems the code stops here, but I don't know for sure.
  objExcel.open "C:\Users\a78208\AppData\Roaming\Microsoft\AddIns\Buffertplatser.xlam"

  objExcel.Run "read_history"
  objExcel.Run "'Buffertplatser.xlam'!Modul1.read_history"
  

  Set xlApp = Nothing 

End Sub 

As you can see I try to run the read_history script and I have tried many things to make it run but I believe it doesn't run due to Excel opening without loading the xlam files.
Excel opens quicker than normal and the add-ins tab is missing:

enter image description here

vs:

enter image description here

The buttons in this menu is added in workbook_open of the xlam file, so it seems the xlam file is not loaded.
However when I look at the add-ins settings, Excel says it is "on".

enter image description here

So, short question. How can I run the xlam script read_history in a new workbook, or run the script read_history_ext in any (if applicable) workbook.
The second script opens a new workbook so it can run in any workbook.

Andreas
  • 23,610
  • 6
  • 30
  • 62
  • 1
    https://stackoverflow.com/q/213375/11683? https://stackoverflow.com/a/46385108/11683? – GSerg Jul 02 '21 at 07:23

1 Answers1

0

Following the second link of GSerg in comments above I managed to get it working with this:

Option Explicit

On Error Resume Next

ExcelMacroExample

Sub ExcelMacroExample() 

  Dim objExcel 

  Set objExcel = CreateObject("Excel.Application")
  objExcel.Visible = True
  objExcel.Workbooks.Open ("C:\Users\a78208\AppData\Roaming\Microsoft\AddIns\Buffertplatser.xlam")
  objExcel.Run "read_history_ext"
  DoEvents
  objExcel.Application.WindowState = xlMaximized


  Set objExcel = Nothing 

End Sub 

The only issue is that it doesn't maximize the window, but I can live with that...

Andreas
  • 23,610
  • 6
  • 30
  • 62