VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA Set Cell Color by Hex CodeTo set an Excel cell’s fill color from a hex value such as #1E90FF, convert its red, green, and blue pairs to…
- Excel VBA: Save a Sheet as a New WorkbookTo save one worksheet as a separate workbook in Excel VBA, copy it without specifying a destination, then save the newly created…
- Excel VBA: Save One Worksheet as a Separate New FileTo save one Excel tab as a separate file with VBA, copy the worksheet into a new workbook, then save that workbook…
- Excel VBA: Select a Range Offset from the Active CellIn Excel VBA, use ActiveCell.Offset(rowOffset, columnOffset).Select to select a cell relative to the active cell; use Resize after Offset when you need…
- Excel VBA: Save a Range as a PNG Image File AutomaticallyTo save an Excel range as an image with VBA, copy the range as a picture, paste it into a temporary chart,…
- Excel VBA SaveCopyAs: Save a Copy Without RenamingIn Excel VBA, use Workbook.SaveCopyAs to save a copy of an open workbook without changing the name or location of the workbook…
- Excel VBA Save As Dialog Box: How to Use ItTo show a Save As dialog from Excel VBA, call Application.GetSaveAsFilename, check whether the user cancelled, and then pass the chosen path…
- Excel VBA Runtime Error 91: Causes and FixesExcel VBA runtime error 91 means your code tried to use an object variable that does not currently refer to an object.…
- Excel VBA Runtime Error 70: Causes and FixesExcel VBA runtime error 70, “Permission denied,” means that a VBA operation was refused access to a file, folder, or other protected…
- Excel VBA Run-Time Error 9 in a For LoopExcel VBA run-time error 9, “Subscript out of range,” means code tried to access an array element or collection item that does…
- Excel VBA Runtime Error 424: Object RequiredExcel VBA Run-time error ‘424’: Object required means a line of code is using a value where VBA expects an object, such…
- Excel VBA: Run a Macro Automatically When a Workbook OpensYes. To run a VBA macro when an Excel workbook opens, put a Workbook_Open event procedure in that workbook’s ThisWorkbook code module,…
- Excel VBA Prompt to Open a File: Code and OptionsTo prompt someone to choose a workbook and then open it in Excel VBA, call Application.GetOpenFilename and pass the selected path to…
- Excel VBA Reference Error: Causes and FixesAn Excel VBA reference error usually means the VBA project depends on a library that Excel cannot find or load. In Excel…
- Excel VBA: Return the Last Used Row Number ReliablyIn Excel VBA, the usual way to get the last row in a particular column is to start at the bottom of…
- Excel VBA: Open XML Files, Read Data, and Handle ErrorsYes. In Excel VBA on Windows, use Workbooks.OpenXML to open an XML file in Excel’s workbook format, or use the MSXML parser…
- Excel VBA Procedure Too Large Error: Causes and FixesThe Excel VBA “Procedure too large” error means a single Sub or Function has grown beyond what the VBA compiler can handle.…
- Excel VBA: Open a VBS File in Edit ModeYes. In Excel for Microsoft 365 on Windows, VBA can open a .vbs file in an editor such as Notepad by launching…
- Excel VBA: Open a Text File for Reading, Step by StepTo open a text file for reading in Excel VBA, assign a free file number, use the Open statement with For Input,…
- Excel VBA: Open a Text File for WritingIn Excel VBA, use Open filePath For Output As #fileNo to create a text file or replace its contents, then write lines…
- Excel VBA: Open a SharePoint File in Edit ModeYes. In Excel for Microsoft 365 on Windows, VBA can ask Excel to open a SharePoint workbook with Workbooks.Open and ReadOnly:=False. That…
- Excel VBA: Open the Latest Downloaded File AutomaticallyYes. In Excel for Microsoft 365 on Windows, a VBA macro can scan your Downloads folder, identify the newest supported Excel file…
- Excel VBA: Open an IQY File Without PromptsYes. In Excel for Microsoft 365 on Windows, VBA can open an .iqy file with Workbooks.Open, while temporarily turning off ordinary Excel…
- Excel VBA: Open the Most Recently Modified File in a FolderTo open the most recently modified Excel workbook in a folder, have VBA compare each eligible file’s modified date and time, then…
- Excel VBA: Open Files with Relative Paths in WorkbooksIn Excel VBA, build a file’s path from the folder containing the macro workbook, then pass that full path to Workbooks.Open. For…
- Excel VBA Open a Given File: Code and OptionsYes. In Excel for Microsoft 365 on Windows, VBA opens a specific workbook with the Workbooks.Open method, supplying its full file path.…
- Excel VBA: Open a File Without Running MacrosTo open an Excel workbook without triggering its automatic macros, hold down Shift as you open it and keep holding the key…
- Excel VBA: Open a File Based on a Cell Value SafelyTo open a workbook whose path is stored in a cell, read that cell into a VBA string and pass the path…
- Excel VBA Open File Dialog: A Practical GuideTo show an Open dialog in Excel VBA, use Application.FileDialog(msoFileDialogFilePicker), set its title and filters, and call .Show. The dialog lets a…
- Excel VBA: Open a File Dialog to Select a FolderTo let someone choose a folder in Excel VBA, use Application.FileDialog(msoFileDialogFolderPicker). Show the dialog, check whether the user clicked OK, and read…