VBA & Macro Problems

Call Excel VBA Macros on Other Worksheets Without Selecting Them

Chanuka GeekiyanageChanuka Geekiyanage Nov 18, 2026 868 views

Question details

Run worksheet-specific receipt formatting procedures from a master printing macro without selecting each worksheet.

Call Excel VBA Macros on Other Worksheets Without Selecting Them
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.
Before you start

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.

Solution 1Recommended

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.

1
Create a standard module

In the VBA editor, select the workbook in Project Explorer and choose Insert > Module.

2
Add a public formatting procedure

In the new module, enter: Public Sub FormatReceipt(ByVal ws As Worksheet) ws.Range("A1:H20").Rows.AutoFit End Sub

3
Call it from the master macro

In the master procedure, add: FormatReceipt ThisWorkbook.Worksheets("GALLONS RECEIPTS"). Repeat the call with other worksheet names as needed, then run the master macro.

Move reusable formatting procedures to a standard VBA module
Avoid unqualified references: When moving existing logic, replace references such as Range or Rows with references qualified by ws. This prevents the procedure from acting on the active sheet by mistake.
Free Microsoft Office alternative

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.

Edit and format receipt worksheets in WPS Spreadsheets.Open common Microsoft Excel formats, including XLSX; macro-enabled XLSM support can vary by version.Use a familiar interface that makes everyday spreadsheet tasks easy to learn.Install a free, lightweight office suite for routine document work.
microsoft office alternative - wps office

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.