Placing Macros on the ribbon

ylafont

New Member
Joined
Jun 21, 2016
Messages
36
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I have an Excel macro that performs a few functions, it takes a excel table from worksheet, creates an array of it contents, performs a mail merge in word, Creates a form, and a few emails(from MS-Word documents). If the macro is executed from the main spreadsheet, where the macro is, everything works normally. I want to place this macro on the ribbon allowing a user to launch it without having (or knowing where the main excel document is located or having to open manually)., Ideally making to check to upgrade the macro at a later date if changes are made.

The user needs to validate the table before the forms are create and I have made several attempts to Open the Spearsheet if it is not open without running the macro or run the macro if the spreadsheet is open. I created a sub to check to see if the spreadsheet was open and modified the ribbon to include an icon for the macro; which works.

However, when launched from the ribbon while the main Excel spreadsheet is not open, it opens the workbook and runs the macro in entirety (Without executing the open workbook line of the macro). I assume the spreadsheet is being open because the macro that is being called resides with it (makes sense). I have also tried to save the worksheet as an excel add-in *.xlam activating it, but found not method of placing an icon on the ribbon to execute the macro. When excel is closed, the check to see if the workflow is open executes.

Does anyone have a recommended approach or best practices? Thank you in advance.

Sub MainForm()

Dim WorkingFolder As String
Dim File01 As String 'Main Excel Data File, where all data is
Dim File02 As String 'Preliminary Email to send to user
Dim File03 As String 'Final Email to Send to user when production is complete
Dim wb As Workbook

WorkingFolder = "C:\Temp\"
File01 = "01-MainData.xlsm"
File02 = "02-PreProductionEmail.docx"
File03 = "03-FinalProductionEmail.docx"

If wbIsOpen(File01) = True Then
MsgBox "Workbook Is Open"
Run - Sub and Functions to create forms and emails
Else

MsgBox "oh oh – not open, opening workbook"
‘Set wk = Workbooks.Open(WorkingFolder & File01)
End If

End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

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