Forum Discussion

SoyAllenChiu's avatar
SoyAllenChiu
Copper Contributor
Jan 23, 2024

Prevent Excel change the column width automatically when opened on different computers

 

Hi there. How can I prevent Excel from changing the column width automatically when opened on different computers?

  • a. Save Column Widths in the Template

    Create a Template: Set up your spreadsheet with the desired column widths.
    Save as Template: Save it as an Excel Template (.xltx) via File > Save As and select Excel Template in the file type dropdown.
    b. Use VBA to Lock Column Widths

    For more control, use VBA to set and lock column widths:

    Open VBA Editor: Press Alt + F11.
    Insert a Module: Go to Insert > Module.
    Add Code: Paste the following code into the module:
    vba
    Copy code
    Private Sub Workbook_Open()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    ws.Columns("A:Z").ColumnWidth = 15 ' Adjust the range and width as needed
    Next ws
    End Sub
    Save Workbook: Save the workbook as a macro-enabled file (.xlsm).

Resources