https://github.com/char16t/build-excel-with-vba
Script for building Excel file with macros on VBA
https://github.com/char16t/build-excel-with-vba
excel vba vba-excel
Last synced: 4 months ago
JSON representation
Script for building Excel file with macros on VBA
- Host: GitHub
- URL: https://github.com/char16t/build-excel-with-vba
- Owner: char16t
- License: unlicense
- Archived: true
- Created: 2019-07-02T09:50:57.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-19T11:08:39.000Z (over 5 years ago)
- Last Synced: 2024-05-22T22:35:08.542Z (11 months ago)
- Topics: excel, vba, vba-excel
- Language: PowerShell
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - char16t/build-excel-with-vba - Script for building Excel file with macros on VBA (PowerShell)
README
This is example of script for building Excel files with macros on VBA. This is an example of how you can store the source code of your VBA projects or various Excel-based programs.
## TL;DR
You may need administrator rights. Run in PowerShell:
```
.\build.ps1
```
or
```
.\build.ps1 -enableRegistryFix
```## Build Excel file with macros
**Enable PowerShell scripts**
If you can't run the build script at all, use the following command to temporarily enable PowerShell scripts for the duration of your PowerShell session:
```
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
```**Trust access to the VBA project object model**
Before you will execute build script you should trust access to the VBA project object model. When you run build script with `-enableRegistryFix` this code will be executed before working with document:
```
$ExcelVersion = $Excel.Version
New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\$ExcelVersion\Excel\Security" -Name AccessVBOM -Value 1 -Force | Out-Null
New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\$ExcelVersion\Excel\Security" -Name VBAWarnings -Value 1 -Force | Out-Null
```this code will be executed after working with document:
```
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Office\$ExcelVersion\Excel\Security" -Name AccessVBOM
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Office\$ExcelVersion\Excel\Security" -Name VBAWarnings
```If you have error when `$book.VBProject.VBComponents.Add(1)` is `NULL` you should use `-enableRegistryFix` flag:
```
.\build.ps1 -enableRegistryFix
```## Unlicense
This is public domain