Executing modules from any workbook

Joined
Oct 15, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I wrote several modules in a workbook called Book1.xlsm. They worked perfectly. I saved the file as an addin. In excel I place a check by this file in excel add-ins. I open a new file and run a module. I get no results, and sometimes an error message. What am I doing wrong? Thanks for any assistance. Here is a simple module for example:

VBA Code:
Sub Fractionate()

''sets column format to fractional
'
   Set ws = ThisWorkbook.Sheets("Sheet1")
'
ws.Columns("A:b").NumberFormat = "# ?/?"

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I have moved this question from the Microsoft Access forum to the Excel Questions forum, as it definitely appears to be an Excel question!
 
Upvote 0
To answer your question, if you are saving this code as an Add-In, I think you will want to change all your references to "ThisWorkbook" (which is the Workbook the VBA code is stored in) to "ActiveWorkbook" (which is the Excel workbook that is active when you try running the code).
 
Upvote 0
Solution
You are welcome.

Many times "ThisWorkbook" and "ActiveWorkbook" are "one and the same", but not in the case where you use Add-Ins.
 
Upvote 0

Forum statistics

Threads
1,223,754
Messages
6,174,315
Members
452,555
Latest member
colc007

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