Using Application.Run Method for Excel Macros

silenus

New Member
Joined
May 24, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I suspect that this is an elementary question, but I have not had to code an application object in the past. There is a single Workbook open, named Test.xlsm, with a single Worksheet, Sheet1. I would like to use the Application.Run Method to run Excel Macros. is the proper way to specify the Application ojbject for use with the Application.Run method. The macro that I wish to run has no parameters. The code:

Sub CodeRun()
Worksheets("Sheet1").Run (Setval)
End Sub

Sub Setval()
Cells(4, 4).Value = 8
End Sub

gives an "Expected Function or Variable" error.

Test.xlsm
D
4
Sheet1


Thanks.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Sorry for the poor grammar above the question should read:
I suspect that this is an elementary question, but I have not had to code an application object in the past. There is a single Workbook open, named Test.xlsm, with a single Worksheet, Sheet1. I would like to use the Application.Run Method to run Excel Macros. What is the proper way to specify the Application ojbject for use with the Application.Run method. The macro that I wish to run has no parameters. The code is:

Sub CodeRun()
Worksheets("Sheet1").Run (Setval)
End Sub

Sub Setval()
Cells(4, 4).Value = 8
End Sub

gives an "Expected Function or Variable" error.

Thanks

Test.xlsm
D
4
Sheet1




Test.xlsm
 
Upvote 0
I would pass the sheet name as a parameter and use Call
VBA Code:
Sub CodeRun()
Call Setval("Sheet1")
End Sub

Sub Setval(strSheetName As String)
Worksheets(strSheetName).Cells(4, 4).Value = 8
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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