Active X button and Public statement

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
379
Office Version
  1. 365
Platform
  1. Windows
Good evening,

For conversion to XML I got a macro. I would like to put this macro in a Active X button, but it refuses to run. (it does run with a normal button) The first error I got is on the Public statement. Now this is a small part of the macro, but can this solved?

Thank you for your time and efforts.

ROmano


Public Itemcode As String
Public SalesPrice As String
Public CostPrice As String
Public SupplierMain As String
Public SupplierCode As String
Public SupplierPrice As String

Public Itemrow As Integer ' Counter for actual row
Public SaveDir As String ' Header Cell (2,2)
Public ItemCurrency As String ' Header Cell (4,2)
Public ItemResource As String ' Header Cell (6,2)
Public Action As Boolean ' Flag
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
There is no clear answer to this because the rest of your code is missing.
The Public statements ensure that variables are declared at project level with a global scope. Therefore the Public statement cannot be used at procedure level (an ActiveX button click event handler is a procedure). Because the variables are declared that way it's quite possible the rest of your code consists of multiple procedures (macros), but we don't know for sure, so changing scope could lead to other issues.

I would recommend that you familiarize yourself with the declaration of variables, their scope and lifetime.

 
Upvote 0
There is no clear answer to this because the rest of your code is missing.
The Public statements ensure that variables are declared at project level with a global scope. Therefore the Public statement cannot be used at procedure level (an ActiveX button click event handler is a procedure). Because the variables are declared that way it's quite possible the rest of your code consists of multiple procedures (macros), but we don't know for sure, so changing scope could lead to other issues.

I would recommend that you familiarize yourself with the declaration of variables, their scope and lifetime.

Good evening,

Thank you for your reply. Not an easy topic but I will try understand it all.

Romano
 
Upvote 0
You are welcome and good luck!
 
Upvote 0

Forum statistics

Threads
1,214,527
Messages
6,120,057
Members
448,940
Latest member
mdusw

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