Active X button and Public statement

Romano_odK

Board Regular
Joined
Jun 4, 2020
Messages
110
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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
2,582
Office Version
  1. 2013
Platform
  1. Windows
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.

 

Romano_odK

Board Regular
Joined
Jun 4, 2020
Messages
110
Office Version
  1. 365
Platform
  1. Windows
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
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
2,582
Office Version
  1. 2013
Platform
  1. Windows
You are welcome and good luck!
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,608
Messages
5,765,402
Members
425,282
Latest member
Nibblesy

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
Top