Insert Integer Variable into file path while assigning macro

rwr5014

New Member
Joined
Jun 4, 2013
Messages
4
Hi all,

In order to assign a macro to an object, I need to specify an Integer variable as part of the file path. How do I do this? I've tried different combinations of quote types/positioning with no luck.

When clicked, I need to run macro "DatabaseScan" from workbook C:\Users\Ryan\Storage\Database(Integer variable).xlsm

How would I go about inputting this?

Selection.OnAction = ????

Thank you for your help.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
you could convert the integer to a string

so for example:

FilePath = "C:\Users\Ryan\Storage\Database" & cstr(integer variable) & ".xlsm"
 
Upvote 0
you could convert the integer to a string

so for example:

FilePath = "C:\Users\Ryan\Storage\Database" & cstr(integer variable) & ".xlsm"

Thanks for the tip, essential. However, your code does not include the macro which is key to answering the question. Do you have any idea on how to fill in the "???" portion of my original post? Thanks!
 
Upvote 0
So... just to get it clear in my head

* you have two (or more) Excel workbooks?
* you want to run a macro called 'DatabaseScan' that is located in workbook1, from workbook2 ?

therefore you want to have the 'DatabaseScan' macro available from multiple Excel workbooks

is this correct?
 
Upvote 0
The object that you are attempting to execute the 'DatabaseScan' macro from... what kind of object is it?


If you did create the object in code it should be as simple as this:

Sub CreateButton()
ActiveSheet.Buttons.Add(200, 46.5, 43.5, 12).Select
Selection.OnAction = "Personal.xlsb!Test"
End Sub


notice that I have my macro 'Test' save in my Personal.xlsb file. This means that the macro can then be accessed from any workbook that is opened in Excel.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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