-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_to_docx.ps1
More file actions
29 lines (26 loc) · 891 Bytes
/
Copy pathconvert_to_docx.ps1
File metadata and controls
29 lines (26 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$files = @(
@{ Source = "d:\project2569\iot_project_proposal.html"; Dest = "d:\project2569\iot_project_proposal.docx" },
@{ Source = "d:\project2569\speaker_invitation.html"; Dest = "d:\project2569\speaker_invitation.docx" }
)
try {
$word = New-Object -ComObject Word.Application
$word.Visible = $false
$word.DisplayAlerts = [Microsoft.Office.Interop.Word.WdAlertLevel]::wdAlertsNone
foreach ($file in $files) {
try {
Write-Host "Converting $($file.Source)..."
$doc = $word.Documents.Open($file.Source)
$doc.SaveAs([ref]$file.Dest, [ref]16)
$doc.Close()
Write-Host "Success: $($file.Dest)"
}
catch {
Write-Error "Failed to convert $($file.Source): $_"
}
}
$word.Quit()
}
catch {
Write-Error "Global error: $_"
if ($word) { $word.Quit() }
}