Call Excel VBA Macros on Other Worksheets Without Selecting Them
Question details
Run worksheet-specific receipt formatting procedures from a master printing macro without selecting each worksheet.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A master macro prepares and prints receipt layouts across several worksheets.
- Observed behavior
- The user wants each formatting procedure to work on its intended worksheet while another sheet remains active.
Open the workbook in Excel and press Alt+F11 to inspect its VBA modules. Identify the receipt sheet names and check whether existing procedures are in standard modules or worksheet code modules.
Move reusable formatting procedures to a standard VBA module
Use a public procedure with a worksheet argument when the same formatting logic should work on multiple receipt sheets.
In the VBA editor, select the workbook in Project Explorer and choose Insert > Module.
In the new module, enter: Public Sub FormatReceipt(ByVal ws As Worksheet) ws.Range("A1:H20").Rows.AutoFit End Sub
In the master procedure, add: FormatReceipt ThisWorkbook.Worksheets("GALLONS RECEIPTS"). Repeat the call with other worksheet names as needed, then run the master macro.

Call a public procedure using the worksheet code name
Use this approach when a procedure should remain in its worksheet's code module.
Work with Receipt Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Office files. It can help you move everyday receipt layout work to WPS, though Excel VBA macro support depends on the WPS version and configuration.

Frequently Asked Questions
Why does my macro change the active sheet instead of the receipt sheet?
Unqualified references such as Range or Rows can refer to the active sheet. Qualify them with a worksheet variable, such as ws.Range("A1:H20"), or use Me inside that worksheet's code module.
How do I find a worksheet's VBA code name?
Press Alt+F11, select the worksheet in Project Explorer, and press F4. The (Name) property is its VBA code name; the Name property is the worksheet tab name.
Can I call a private worksheet procedure from a standard module?
No. Change the procedure declaration from Private Sub to Public Sub, then call it using the worksheet code name, such as Sheet1.FormatReceipt.
Which workbook format should I use to keep the macros?
In Excel, choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm). Enable macros only when you trust the workbook.




