Need to set up a constant

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,589
Office Version
  1. 2021
Platform
  1. Windows
I have set up a constant as follows



Code:
 Const C As String = .xlsm
Sub Open_Fies ()
Windows("M_ERT Sales(P).xls").Activate
    Application.Run "'M_ERT Sales (P).xls'!Data_INPUT"
    ActiveWorkbook.Close
     Windows("M_ERT Sales (P)" & "C &").Activate
     ActiveWorkbook.Close
    Windows("Open Sales Data Files.xlsm").Activate
 End Sub

I get an invalid reference and code below highlighted

Code:
 Const C As String = .xlsm


It would be appreciated if someone could correct this
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You're missing quotes:

Code:
Const C As String = ".xlsm"

Also, the usage should be:

Code:
Windows("M_ERT Sales (P)" & C).Activate

not that you need to activate it to close it.
 
Upvote 0
Thanks for the help Rory

I need some further help


I have a macro which I want to run that is in the source workbook, but get a run time error

See code highlighted when debugging


Code:
Application.Run "'M_ERT Sales(P) " & C '!Data_INPUT

Code:
 Const C As String = ".xlsm"

Sub Open_Files ()
Windows("'M_ERT Sales(P)" & C).Activate
     Application.Run "'M_ERT Sales(P) " & C '!Data_INPUT"
    ActiveWorkbook.Close
     Windows("'M_ERT Sales (P)" & C).Activate
     ActiveWorkbook.Close
    Windows("Open Sales Data Files.xlsm").Activate



If change the code to and then run the macro , it works perfectly


Code:
 Application.Run "'M_ERT Sales(P).xlsm'!Data_INPUT"


It would be appreciated if you can amend this part of the code to include the constant
 
Upvote 0
Hi Rory

I managed to sort it out through trial & error


Code:
 Application.Run "'M_ERT Sales(P)" & C & "'!Data_INPUT"
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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