Skip to content

Add Excel and Word Objects support #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions scripts/Build-VBA.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Load utiliies
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$scriptPath/utils/Screenshot.ps1"
. "$scriptPath/utils/Path.ps1"
. "$scriptPath/utils/Object-Import.ps1"

# Args
$folderName = $args[0]
Expand All @@ -22,10 +24,6 @@ if (-not $officeAppName) {
exit 1
}

# Import utility functions
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$scriptPath/utils/Path.ps1"

$currentDir = (Get-Location).Path + "/"
$srcDir = GetAbsPath -path $folderName -basePath $currentDir

Expand Down Expand Up @@ -134,6 +132,14 @@ Write-Host "Module folder path: $moduleFolder"
$classModulesFolder = GetAbsPath -path "$folderName/Class Modules" -basePath $currentDir
Write-Host "Class Modules folder path: $classModulesFolder"

# Define Microsoft Excel Objects folder path
$excelObjectsFolder = GetAbsPath -path "$folderName/Microsoft Excel Objects" -basePath $currentDir
Write-Host "Microsoft Excel Objects folder path: $excelObjectsFolder"

# Define Microsoft Word Objects folder path
$wordObjectsFolder = GetAbsPath -path "$folderName/Microsoft Word Objects" -basePath $currentDir
Write-Host "Microsoft Word Objects folder path: $wordObjectsFolder"

# Define the forms folder path
$formsFolder = GetAbsPath -path "$folderName/Forms" -basePath $currentDir
Write-Host "Forms folder path: $formsFolder"
Expand All @@ -159,6 +165,20 @@ if (-not (Test-Path $formsFolder)) {
Write-Host "Created forms folder: $formsFolder"
}

#Check if the Microsoft Excel Objects folder does not exist create an empty one (only for Excel)
if ($officeAppName -eq "Excel" -and (-not (Test-Path $excelObjectsFolder))) {
Write-Host "Microsoft Excel Objects folder not found: $excelObjectsFolder"
New-Item -ItemType Directory -Path $excelObjectsFolder -Force | Out-Null
Write-Host "Created Microsoft Excel Objects folder: $excelObjectsFolder"
}

#Check if the Microsoft Word Objects folder does not exist create an empty one (only for Word)
if ($officeAppName -eq "Word" -and (-not (Test-Path $wordObjectsFolder))) {
Write-Host "Microsoft Word Objects folder not found: $wordObjectsFolder"
New-Item -ItemType Directory -Path $wordObjectsFolder -Force | Out-Null
Write-Host "Created Microsoft Word Objects folder: $wordObjectsFolder"
}

# Get VBProject once and reuse it for all imports
$vbProject = $null
try {
Expand Down Expand Up @@ -199,7 +219,25 @@ try {
exit 1
}

# Import class modules first (.cls files)
# Check if we have application-specific objects to import
$objectsFolder = $null
if ($officeAppName -eq "Excel") {
$objectsFolder = $excelObjectsFolder
} elseif ($officeAppName -eq "Word") {
$objectsFolder = $wordObjectsFolder
}

if ($objectsFolder -and (Test-Path $objectsFolder)) {
$importResult = Import-ObjectCode -officeAppName $officeAppName -vbProject $vbProject -objectsFolder $objectsFolder -screenshotDir $screenshotDir -fileNameNoExt $fileNameNoExt

if (-not $importResult) {
Write-Host "🔴 Error: Failed to import $officeAppName object code"
Take-Screenshot -OutputPath "${screenshotDir}Screenshot_${fileNameNoExt}_{{timestamp}}.png"
exit 1
}
}

# Import class modules (.cls files)
$clsFiles = Get-ChildItem -Path $classModulesFolder -Filter *.cls -ErrorAction SilentlyContinue
Write-Host "Found $($clsFiles.Count) .cls files to import"

Expand Down Expand Up @@ -360,5 +398,3 @@ try {
} catch {
Write-Host "Warning: Error releasing document COM object: $($_.Exception.Message)"
}


Loading