Yes. In Excel for Microsoft 365 on Windows, VBA can open a .vbs file in an editor such as Notepad by launching the editor with the script’s path. A .vbs file is VBScript, not an Excel VBA module, so Excel’s Visual Basic Editor cannot open it as a native VBA project.
What “edit mode” means for a VBS file
People asking how to open a VBS file in edit mode usually want to display its source code in a text editor, rather than run the script. Those are different actions: an editor lets you read and change the file, while Windows Script Host or another script host interprets and runs it. The safest way for a macro to open a script for editing is to launch a named editor explicitly and pass the file path as an argument.
Excel VBA and VBScript share much of their Visual Basic–style syntax, but they are different languages with different environments. VBA code belongs to an Office host such as Excel and is stored in a workbook or add-in. VBScript is normally stored in a .vbs text file and run by a Windows script host or a program that supports it. You can inspect or edit a .vbs file from Excel, but you cannot load it into the VBA editor as if it were a standard module.
Open a VBS file in Notepad from Excel VBA
This example asks the user to choose a .vbs file and opens it in Windows Notepad. It uses the Windows Script Host automation object to launch Notepad without waiting for the editor to close. The path is quoted so that it still works when a folder or filename contains spaces.
Sub OpenVbsInNotepad()
Dim selectedPath As String
Dim shellObject As Object
' Save a copy of the workbook before running this macro.
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Choose a VBScript file"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "VBScript files", "*.vbs"
If .Show <> -1 Then Exit Sub
selectedPath = .SelectedItems(1)
End With
Set shellObject = CreateObject("WScript.Shell")
shellObject.Run "notepad.exe " & Chr$(34) & selectedPath & Chr$(34), 1, False
Set shellObject = Nothing
End Sub
Put the procedure in a standard module in the Excel Visual Basic Editor, then run it from Excel with Developer > Macros, or assign it to a button. If the Developer tab is not visible, enable it through File > Options > Customize Ribbon and select Developer. The file picker limits the displayed choices to .vbs files, but it does not validate the script’s contents; a renamed or unusual file should still be treated cautiously.
The second argument to Run is the window style: 1 asks for a normal window. The final argument, False, means the macro does not wait for Notepad to close. If you change that argument to True, VBA waits until the editor exits before continuing. This is rarely necessary for simply opening a script, and waiting does not tell Excel whether the file was saved.
Use a fixed file path instead
If the script’s location is known and does not change, you can replace the file-picker section with a fixed path. Check that the file exists before launching the editor so that a typo produces a useful message instead of an empty or confusing result.
Sub OpenKnownVbsInNotepad()
Dim filePath As String
Dim shellObject As Object
' Save a copy of the workbook before running this macro.
filePath = "C:\Scripts\Example Script.vbs"
If Len(Dir$(filePath)) = 0 Then
MsgBox "The VBS file was not found: " & filePath, vbExclamation
Exit Sub
End If
Set shellObject = CreateObject("WScript.Shell")
shellObject.Run "notepad.exe " & Chr$(34) & filePath & Chr$(34), 1, False
Set shellObject = Nothing
End Sub
Change the example path to the actual location of the file. The quotes around the path in the command are important: without them, a path such as C:\Scripts\Example Script.vbs can be interpreted as multiple command-line arguments. Do not put quotation marks inside the value assigned to filePath; the macro adds the required command-line quotes when it starts Notepad.
Choose the editor you want to use
Notepad is a simple default because it is included with Windows and can display and edit plain-text scripts. If you prefer another editor, replace notepad.exe with the editor’s executable name or full executable path. For example, a code editor may need to be installed first, and its command-line options can differ by product and installation. Test the command with a harmless sample file before relying on it in a workflow.
When an editor’s executable path itself contains spaces, quote that path as well as the script path. The exact command-line structure depends on the editor: some accept a file path directly, while others provide options for opening a new window or reusing an existing one. Avoid assuming that every editor accepts Notepad’s command format. If you want to use the Windows default application associated with .vbs files, be especially careful: that association may run the script instead of opening it for editing.
What Excel VBA can and cannot do
Opening the file in Notepad does not make Excel the editor and does not import the script into the workbook. It simply starts another Windows application and gives it a file path. The user makes edits and saves them from that application. The Excel macro does not automatically know whether the file was changed, saved, or closed unless you build additional processes around it.
Likewise, a .vbs file cannot be opened as a VBA project by choosing File > Open in the Visual Basic Editor. The VBE is designed for VBA code hosted by Office, not for editing arbitrary VBScript files. You can copy compatible code between environments manually, but compatibility is not guaranteed: VBScript and VBA differ in available objects, functions, language features, and how they interact with the operating system or host application.
Opening a script in an editor is also not the same as executing it. Do not use Shell with the .vbs file itself as the program if your goal is to edit it. Nor should you use a command that explicitly invokes a script host, such as wscript.exe or cscript.exe, for that purpose. Those commands are intended to run scripts, not present their source for editing.
Safety and file-handling considerations
A script can contain commands that change files, access network locations, or perform other actions when executed. Opening it in Notepad to inspect the source does not run those commands, but later double-clicking the file or launching it through a script host may. If the file came from an unfamiliar source, do not run it merely to see what it does. Review its contents first and follow your organization’s security procedures.
- Save a copy of the Excel workbook before running a macro. VBA changes to a workbook cannot generally be reversed with Ctrl+Z.
- Use an explicit text editor, rather than the .vbs file association, when the goal is inspection or editing.
- Keep a backup of the script before making changes, especially if another process or person depends on it.
- Check the chosen file path before saving, so you do not overwrite a different script by mistake.
- Be mindful of encoding. A text editor may display or save a script using a different character encoding; check the editor’s encoding options if the file contains non-English text or special characters.
The macro above launches Notepad; it does not alter the script’s contents itself. Saving edits is a separate action inside Notepad. If the file is on a shared drive, another user or process could also change it, so the version open in the editor may not remain the only copy.
Common problems and fixes
Notepad does not open. Confirm that the macro is running on Windows and that the selected path points to an accessible file. If the script is on a network drive, check the connection and permissions. A Windows security policy may also restrict automation or script-related tools; do not try to bypass a managed policy.
The macro says the file is missing. For the fixed-path example, check spelling, the drive letter, the folder, and the extension. Windows File Explorer may hide known extensions, so a file that appears to be named Example Script.vbs could have a different actual name. The file-picker version can help avoid path-typing errors.
A path with spaces fails. Keep the quotation marks added by Chr$(34) around the full selected path. If you change the command to use a different editor, check that editor’s documentation for how it expects paths and options to be quoted.
The script runs instead of opening. The macro may be launching the .vbs file through its file association or through a script host. Use the explicit Notepad command shown above. A double-click in File Explorer may also run a .vbs file depending on the system configuration, so use a right-click editing option or open Notepad first when working outside Excel.
Excel blocks the macro. The workbook must be saved in a macro-enabled format, such as .xlsm, if it contains VBA that needs to persist. Excel’s macro security settings and organizational policies determine whether code can run. Only enable macros in workbooks you trust; lowering security settings globally is not a suitable fix.
Windows, Mac, and Excel for the web
The code examples are for Excel for Microsoft 365 on Windows. They rely on Windows Script Host through CreateObject("WScript.Shell") and launch the Windows program Notepad. They are not portable VBA code for Excel on Mac. On a Mac, use Finder’s Open With option or open the .vbs file from a text editor such as TextEdit or another code editor installed on that Mac. VBScript is a Windows scripting technology, so opening its text on a Mac does not make it runnable there.
Excel for the web cannot run VBA macros. If you are using Excel in a browser, download or open the workbook in the desktop version of Excel for Windows to use the macro, subject to your organization’s security settings. If you only need to inspect the script, opening it directly in a text editor is simpler than involving Excel.
Frequently Asked Questions
Can Excel VBA open a VBS file in the VBA editor?
No. The Visual Basic Editor handles VBA projects, while a .vbs file contains VBScript. Use a text editor such as Notepad to inspect or edit the file.
How do I open a VBS file without running it?
Launch a text editor explicitly and pass the script path to it, as in the Notepad macro above. Do not launch the .vbs file itself or call wscript.exe or cscript.exe when you only want to read the source.
Can I open the VBS file in VS Code from VBA?
Yes, if VS Code is installed and you use its executable or command-line launcher with the file path. The executable location and supported options depend on the installation, so use the editor’s documented command format and quote paths correctly.
Will changes in Notepad update automatically in Excel?
No. The editor changes the external .vbs file, not the Excel workbook. Save the file in Notepad, and reopen or reload it in any application that needs to read the updated script.
Can this macro work in Excel for Mac?
Not as written. It uses Windows Script Host and Notepad, neither of which is the Mac equivalent. Open the file in a Mac text editor instead, or create a separate Mac-specific solution.
Related
- Excel Uppercase to Lowercase Shortcut: What Actually Works
- Excel Unmerge Cells Shortcut: Keys, Steps, and Fixes
- Excel Unmerge Cells and Fill Every Cell with Its Data
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Method to Sort Data in ExcelThe VBA method to sort data in Excel is the Sort object, configured with a sort key, a…
- VBA Code to Sort Data by Multiple ColumnsTo sort Excel rows by multiple columns with VBA, use the worksheet’s Sort object, add one sort field…
- Excel VBA: Delete a Worksheet Without a Prompt SafelyTo delete an Excel worksheet without the confirmation prompt, set Application.DisplayAlerts to False immediately before calling the worksheet’s…
- Excel VBA Dim As Workbook: Declare and Use ItIn Excel VBA, declare a workbook variable with Dim wb As Workbook, then assign it to an open…
- Excel VBA: Find the First Non-Empty Row in a ColumnTo find the first non-empty row in an Excel column with VBA, use the range’s Find method with…
- Date Data Validation in Excel VBA: Rules and ExamplesTo restrict a range to dates with Excel VBA, use each cell’s Validation object and add a date…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.