Я хочу написать скрипт Powershell, который открывает существующий файл и помещает в него макрос.
Я ищу и ищу, но ничего не нашел.
Мой код:
$Word = New-Object -ComObject Word.Application
$Word.Visible = $true
$filepathagenda = "C:\Users\$Username\Desktop\Agenda.docx"
$Word.Documents.Open($filepathagenda)
Код VBA:
Sub Macroname()
Dim oTab As Table
Dim i As Integer
Dim x As Integer
Dim Std As Double
Dim Min As Double
Dim Dauer As Double
Dim Z As Double
Dim ZInt As Double
Dim ZDez As Double
Dim Txt As String
Set oTab = ActiveDocument.Tables(1)
i = oTab.Rows.Count
For x = 2 To i
On Error GoTo ErrorHandle:
Std = CDbl(Left(oTab.Cell(x, 5), 2))
Min = CDbl(Mid(oTab.Cell(x, 5), 4, 2))
Txt = oTab.Cell(x, 4).Range.Text
Dauer = CDbl(Left(oTab.Cell(x, 4), Len(Txt) - 2))
If Min + Dauer < 60 Then
oTab.Cell(x + 1, 5).Range.Text = Format(Std, "00") & ":" & Format(Min + Dauer, "00")
oTab.Cell(x + 1, 5).Select
Else
Z = (Min + Dauer) / 60
ZDez = Z - Int(Z)
ZDez = ZDez * 60
oTab.Cell(x + 1, 5).Range.Text = Format(Std + Int(Z), "00") & ":" & Format(ZDez, "00")
oTab.Cell(x + 1, 5).Select
End If
GoTo NoError:
ErrorHandle:
oTab.Cell(x + 1, 5).Range.Text = Format(Std, "00") & ":" & Format(Min, "00")
oTab.Cell(x + 1, 5).Select
Resume NoError:
NoError:
Next x
Ende:
End Sub
Как я могу поместить макрос в файл?
Я только что нашел несколько команд, где я могу запустить макрос, но ничего о внедрении макроса в файл, подобный этому.
После того, как скрипт вставлен в файл docx / docm, я хочу запустить макрос в файле с:
$word.run("Macroname")
$word.quit() exit application