Skip to content

Commit 5914d90

Browse files
authored
Merge pull request #7 from DecimalTurn/dev-ppam
2 parents 9e749b8 + 80c81e1 commit 5914d90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4046
-28
lines changed

Main.ps1

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Get-OfficeApp {
2929
switch -Regex ($FileExtension.ToLower()) {
3030
'^(xlsb|xlsm||xltm|xlam)$' { return "Excel" }
3131
'^(docm|dotm)$' { return "Word" }
32-
'^(pptm|potm)$' { return "PowerPoint" }
32+
'^(pptm|potm|ppam)$' { return "PowerPoint" }
3333
'^(accdb|accda)$' { return "Access" }
3434
default { return $null }
3535
}
@@ -85,7 +85,8 @@ Minimize-Window "Administrator: C:\actions"
8585
Write-Host "========================="
8686

8787
foreach ($folder in $folders) {
88-
$app = Get-OfficeApp -FileExtension $folder.Substring($folder.LastIndexOf('.') + 1)
88+
$fileExtension = $folder.Substring($folder.LastIndexOf('.') + 1)
89+
$app = Get-OfficeApp -FileExtension $fileExtension
8990

9091
if ($app -eq "Access") {
9192
Write-Host "Access is not supported at the moment. Skipping..."
@@ -103,15 +104,23 @@ foreach ($folder in $folders) {
103104

104105
Write-Host "Importing VBA code into Office document"
105106
. "$PSScriptRoot/scripts/Build-VBA.ps1" "${SourceDir}/${folder}" "$app"
106-
107-
if ($TestFramework -ieq "rubberduck") {
107+
if ($LASTEXITCODE -ne 0) {
108+
Write-Host "Build-VBA.ps1 failed with exit code $LASTEXITCODE"
109+
exit $LASTEXITCODE
110+
}
111+
112+
if ($TestFramework -ieq "rubberduck" -and $fileExtension -ne "ppam") {
108113
Write-Host "Running tests with Rubberduck"
109114
$rubberduckTestResult = Test-WithRubberduck -officeApp $officeApp
110115
if (-not $rubberduckTestResult) {
111116
Write-Host "Rubberduck tests were not completed successfully, but continuing with the script..."
112117
}
113118
} else {
114-
Write-Host "Test framework is not Rubberduck. Skipping tests."
119+
if ($fileExtension -eq "ppam") {
120+
Write-Host "Skipping tests for PowerPoint add-in (.ppam) files since Rubberduck can't run tests on them directly."
121+
} else {
122+
Write-Host "Test framework is not Rubberduck. Skipping tests."
123+
}
115124
}
116125

117126
Write-Host "Cleaning up"

scripts/Build-VBA.ps1

Lines changed: 80 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ if ($outputFilePath.EndsWith(".xlsb")) {
3838
$outputFilePath = $outputFilePath -replace "\.xlsb$", ".xlsb.xlsm"
3939
}
4040

41+
if ($outputFilePath.EndsWith(".ppam")) {
42+
$outputFilePath = $outputFilePath -replace "\.ppam$", ".ppam.pptm"
43+
}
44+
4145
# Make sure the output file already exists
4246
if (-not (Test-Path $outputFilePath)) {
4347
Write-Host "🔴 Error: Output file not found: $outputFilePath"
@@ -284,22 +288,41 @@ $basFiles | ForEach-Object {
284288

285289
# Save the document
286290
Write-Host "Saving document..."
291+
$oldFilePath = ""
287292
try {
288-
if ($officeAppName -eq "PowerPoint" -or $officeAppName -eq "Word") {
293+
if ($officeAppName -eq "Word") {
289294
# For PowerPoint, use SaveAs with the same file name to force save
290295
$doc.SaveAs($outputFilePath)
291296
Write-Host "Document saved using SaveAs method"
297+
} elseif ($officeAppName -eq "PowerPoint") {
298+
# For PowerPoint, we need to check if the file name ends with .ppam.pptm
299+
# If so, we need to save as .ppam
300+
if ($outputFilePath.EndsWith(".ppam.pptm")) {
301+
$oldFilePath = $outputFilePath
302+
$outputFilePath = $outputFilePath -replace "\.ppam\.pptm$", ".ppam"
303+
# Replace forward slashes with backslashes
304+
$outputFilePath = $outputFilePath -replace "/", "\"
305+
Write-Host "Saving document as .ppam: $outputFilePath"
306+
$doc.SaveAs($outputFilePath, 18) # 18 is the ppSaveAsOpenXMLAddIn file format for .ppam
307+
# Delete the .ppam.pptm file
308+
Remove-Item -Path $oldFilePath -Force
309+
Write-Host "Document saved as .ppam"
310+
} else {
311+
$doc.Save()
312+
Write-Host "Document saved successfully"
313+
}
292314
} elseif ($officeAppName -eq "Excel") {
293315
# For Excel, we need to check if the file name ends with .xlsb.xlsm
294316
# If so, we need to save as .xlsb
295317
if ($outputFilePath.EndsWith(".xlsb.xlsm")) {
296-
$newFilePath = $outputFilePath -replace "\.xlsb\.xlsm$", ".xlsb"
318+
$oldFilePath = $outputFilePath
319+
$outputFilePath = $outputFilePath -replace "\.xlsb\.xlsm$", ".xlsb"
297320
# Replace forward slashes with backslashes
298-
$newFilePath = $newFilePath -replace "/", "\"
299-
Write-Host "Saving document as .xlsb: $newFilePath"
300-
$doc.SaveAs($newFilePath, 50) # 50 is the xlExcel12 file format for .xlsb
321+
$outputFilePath = $outputFilePath -replace "/", "\"
322+
Write-Host "Saving document as .xlsb: $outputFilePath"
323+
$doc.SaveAs($outputFilePath, 50) # 50 is the xlExcel12 file format for .xlsb
301324
# Delete the .xlsb.xlsm file
302-
Remove-Item -Path $outputFilePath -Force
325+
Remove-Item -Path $oldFilePath -Force
303326
Write-Host "Document saved as .xlsb"
304327
} else {
305328
$doc.Save()
@@ -316,8 +339,11 @@ try {
316339
# Alternative approach for PowerPoint if SaveAs fails
317340
if ($officeAppName -eq "PowerPoint") {
318341
try {
342+
343+
$ppFileExtension = $outputFilePath.Substring($outputFilePath.LastIndexOf('.') + 1)
344+
319345
# Try saving with a temporary file name and then renaming
320-
$tempPath = [System.IO.Path]::GetTempFileName() -replace '\.tmp$', '.pptm'
346+
$tempPath = [System.IO.Path]::GetTempFileName() -replace '\.tmp$', ".$ppFileExtension"
321347
Write-Host "Attempting to save to temporary location: $tempPath"
322348
$doc.SaveAs($tempPath)
323349

@@ -326,40 +352,71 @@ try {
326352
$officeApp.Quit()
327353

328354
# Release COM objects
329-
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($doc) | Out-Null
330-
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($officeApp) | Out-Null
355+
# Note: Initially, we were releasing the COM objects here, but since we want to use $doc later in the script to call the WriteToFile macro,
356+
# we will not release them here. Instead, we will release them at the end of the script. Hopefully, this will still allow the SaveAs issue to be resolved.
357+
# [System.Runtime.Interopservices.Marshal]::ReleaseComObject($doc) | Out-Null
358+
# [System.Runtime.Interopservices.Marshal]::ReleaseComObject($officeApp) | Out-Null
331359

332360
# Wait a moment for resources to be released
333-
Start-Sleep -Seconds 2
361+
Start-Sleep -Seconds 5
334362

335363
# Copy the temp file to the intended destination
336364
Copy-Item -Path $tempPath -Destination $outputFilePath -Force
337365
Remove-Item -Path $tempPath -Force
338-
366+
339367
Write-Host "Document saved using alternative method"
340-
341-
# Skip the rest of the cleanup as we've already done it
342-
Write-Host "VBA import completed successfully."
343-
exit 0
368+
369+
if ($oldFilePath) {
370+
# If we had an old file path, delete it
371+
Remove-Item -Path $oldFilePath -Force
372+
Write-Host "Old file deleted: $oldFilePath"
373+
}
374+
375+
# Reopen the office application
376+
$officeApp = New-Object -ComObject "$officeAppName.Application"
377+
$officeApp.Visible = $true
378+
Write-Host "Reopened $officeAppName application"
379+
380+
# Reopen the document, but if it's an Addin, we use Addins.Add then we load it
381+
if ($outputFilePath.EndsWith(".ppam")) {
382+
$doc = $officeApp.AddIns.Add($outputFilePath)
383+
} else {
384+
$doc = $officeApp.Presentations.Open($outputFilePath, $false, $false, $true) # ReadOnly, Untitled, WithWindow
385+
}
386+
387+
Write-Host "Document reopened successfully after alternative save method"
388+
344389
} catch {
345390
Write-Host "Error: Alternative save method also failed: $($_.Exception.Message)"
346391
Take-Screenshot -OutputPath "${screenshotDir}Screenshot_${fileNameNoExt}_{{timestamp}}.png"
347392
}
348393
}
349394
}
350395

351-
# Generic test
396+
if ($officeAppName -eq "PowerPoint" -and $outputFilePath.EndsWith(".ppam")) {
397+
# Check for and remove any PowerPoint Addin folder that might have been created
398+
$presentationName = [System.IO.Path]::GetFileNameWithoutExtension($outputFilePath)
399+
$presentationDir = [System.IO.Path]::GetDirectoryName($outputFilePath)
400+
$possibleAddinFolder = Join-Path -Path $presentationDir -ChildPath $presentationName
401+
402+
if (Test-Path -Path $possibleAddinFolder -PathType Container) {
403+
Write-Host "Removing auto-generated folder: $possibleAddinFolder"
404+
Remove-Item -Path $possibleAddinFolder -Recurse -Force
405+
}
406+
}
407+
352408
# Call the WriteToFile macro to check if the module was imported correctly
353409
try {
354410

355-
$vbaModule = $doc.VBProject.VBComponents.Item(1)
356-
if ($null -eq $vbaModule) {
357-
Write-Host "Error: No VBA module found in the document."
358-
Take-Screenshot -OutputPath "${screenshotDir}Screenshot_${fileNameNoExt}_{{timestamp}}.png"
359-
exit 1
411+
# Adding a slide duplication step similar to the working VBScript example from https://www.msofficeforums.com/powerpoint/23672-calling-macro-powerpoint-command-line.html#post74116
412+
# This seems to be required for the macro to execute properly in PowerPoint
413+
if ($fileExtension -eq "pptm") {
414+
$Slide = $doc.Slides(1).Duplicate()
415+
} elseif ($fileExtension -eq "ppam") {
416+
# Ensure the Addin is loaded
417+
$doc.Loaded = $true
360418
}
361-
Write-Host "VBA module found: $($vbaModule.Name)"
362-
419+
363420
$macroName = "WriteToFile"
364421
Write-Host "Macro to execute: $macroName"
365422
Write-Host "Application state before macro execution: Type=$($officeApp.GetType().FullName)"

scripts/Rename-It.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ if ($fileExtension -eq "xlsb") {
2626
$fileExtension = "xlsb.xlsm"
2727
}
2828

29+
# Since we can't edit the .ppam file directly, we will use the .pptm file extension
30+
if ($fileExtension -eq "ppam") {
31+
$fileExtension = "ppam.pptm"
32+
}
33+
2934
# Create a copy of the zip/document file in the $folderName/Skeleton folder at the top level
3035
$copySource = "$folderName/Skeleton/$fileName.$ext"
3136
$renameDestinationFolder = "$sourceDir/out"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Attribute VB_Name = "Module1"
2+
3+
'@Lang VBA
4+
Option Explicit
5+
6+
Sub Demo()
7+
MsgBox "Hello, World!"
8+
End Sub
9+
10+
'This code will be called via COM to test if the VBA import was successful
11+
Sub WriteToFile()
12+
Dim filePath As String
13+
Dim fileNum As Integer
14+
15+
' Specify the path to the text file
16+
filePath = ThisAddin.Path & "\PowerPointAddin.txt"
17+
18+
' Get a free file number
19+
fileNum = FreeFile
20+
21+
' Open the file for output
22+
Open filePath For Output As #fileNum
23+
24+
' Write some text to the file
25+
Print #fileNum, "Hello, World!"
26+
27+
' Close the file
28+
Close #fileNum
29+
End Sub
30+
31+
Private Function ThisAddin() As PowerPoint.Addin
32+
' This function returns the current Addin object
33+
' It is used to access the Addin's properties and methods
34+
Dim addin As PowerPoint.Addin
35+
36+
For Each addin In Application.AddIns
37+
If addin.Name = "PowerPointAddin" Then
38+
Set ThisAddin = addin
39+
Exit Function
40+
End If
41+
Next addin
42+
' If the addin is not found, return Nothing
43+
Set ThisAddin = Nothing
44+
Exit Function
45+
46+
End Function
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
3+
<Default Extension="jpeg" ContentType="image/jpeg" />
4+
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
5+
<Default Extension="xml" ContentType="application/xml" />
6+
<Override PartName="/ppt/presentation.xml" ContentType="application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml" />
7+
<Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml" />
8+
<Override PartName="/ppt/slides/slide1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml" />
9+
<Override PartName="/ppt/presProps.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presProps+xml" />
10+
<Override PartName="/ppt/viewProps.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml" />
11+
<Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml" />
12+
<Override PartName="/ppt/tableStyles.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml" />
13+
<Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
14+
<Override PartName="/ppt/slideLayouts/slideLayout2.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
15+
<Override PartName="/ppt/slideLayouts/slideLayout3.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
16+
<Override PartName="/ppt/slideLayouts/slideLayout4.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
17+
<Override PartName="/ppt/slideLayouts/slideLayout5.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
18+
<Override PartName="/ppt/slideLayouts/slideLayout6.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
19+
<Override PartName="/ppt/slideLayouts/slideLayout7.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
20+
<Override PartName="/ppt/slideLayouts/slideLayout8.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
21+
<Override PartName="/ppt/slideLayouts/slideLayout9.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
22+
<Override PartName="/ppt/slideLayouts/slideLayout10.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
23+
<Override PartName="/ppt/slideLayouts/slideLayout11.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml" />
24+
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
25+
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" />
26+
</Types>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
3+
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml" />
4+
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail" Target="docProps/thumbnail.jpeg" />
5+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml" />
6+
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml" />
7+
</Relationships>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
3+
<TotalTime>2</TotalTime>
4+
<Words>0</Words>
5+
<Application>Microsoft Office PowerPoint</Application>
6+
<PresentationFormat>Widescreen</PresentationFormat>
7+
<Paragraphs>0</Paragraphs>
8+
<Slides>1</Slides>
9+
<Notes>0</Notes>
10+
<HiddenSlides>0</HiddenSlides>
11+
<MMClips>0</MMClips>
12+
<ScaleCrop>false</ScaleCrop>
13+
<HeadingPairs>
14+
<vt:vector size="6" baseType="variant">
15+
<vt:variant>
16+
<vt:lpstr>Fonts Used</vt:lpstr>
17+
</vt:variant>
18+
<vt:variant>
19+
<vt:i4>3</vt:i4>
20+
</vt:variant>
21+
<vt:variant>
22+
<vt:lpstr>Theme</vt:lpstr>
23+
</vt:variant>
24+
<vt:variant>
25+
<vt:i4>1</vt:i4>
26+
</vt:variant>
27+
<vt:variant>
28+
<vt:lpstr>Slide Titles</vt:lpstr>
29+
</vt:variant>
30+
<vt:variant>
31+
<vt:i4>1</vt:i4>
32+
</vt:variant>
33+
</vt:vector>
34+
</HeadingPairs>
35+
<TitlesOfParts>
36+
<vt:vector size="5" baseType="lpstr">
37+
<vt:lpstr>Aptos</vt:lpstr>
38+
<vt:lpstr>Aptos Display</vt:lpstr>
39+
<vt:lpstr>Arial</vt:lpstr>
40+
<vt:lpstr>Office Theme</vt:lpstr>
41+
<vt:lpstr>PowerPoint Presentation</vt:lpstr>
42+
</vt:vector>
43+
</TitlesOfParts>
44+
<Company>
45+
</Company>
46+
<LinksUpToDate>false</LinksUpToDate>
47+
<SharedDoc>false</SharedDoc>
48+
<HyperlinksChanged>false</HyperlinksChanged>
49+
<AppVersion>16.0000</AppVersion>
50+
</Properties>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
<dc:title>
4+
</dc:title>
5+
<dc:creator>Martin Leduc</dc:creator>
6+
<cp:lastModifiedBy>Martin Leduc</cp:lastModifiedBy>
7+
<cp:revision>1</cp:revision>
8+
<dcterms:created xsi:type="dcterms:W3CDTF">2025-04-19T01:26:16Z</dcterms:created>
9+
<dcterms:modified xsi:type="dcterms:W3CDTF">2025-04-19T01:28:20Z</dcterms:modified>
10+
</cp:coreProperties>
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
3+
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps" Target="presProps.xml" />
4+
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide1.xml" />
5+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="slideMasters/slideMaster1.xml" />
6+
<Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles" Target="tableStyles.xml" />
7+
<Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml" />
8+
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps" Target="viewProps.xml" />
9+
</Relationships>

0 commit comments

Comments
 (0)