有没有可以快速将VBS代码转换为PowerShell代码的软件或工具?
另外,我想知道的是,以下With
VBS代码中的语句,在PowerShell中如何表达?
The With
语句很棒,可以缩短代码,我可以在PowerShell中实现类似的功能吗?
我发现PowerShell代码非常简洁,我很好奇,想知道上面的代码,如何使用最短的PowerShell代码来实现相同的功能。
'declare and instaciate wrdApp
Dim wrdApp: Set wrdApp = WScript.CreateObject("Word.Application")
'declare wrdDoc
Dim wrdDoc
Dim wdReplaceAll
'Open the document
Set wrdDoc = wrdApp.Documents.Open("c:\test.docx")
'set the value for the replace "constant"
wdReplaceAll = 2
wrdDoc.Select
With wrdApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "WordToReplace"
.Replacement.Text = "ReplaceWith"
.Forward = True
.Wrap = 1
.Format = False
.MatchCase = False
.MatchWholeWord = False
'the Replace argument is the 11'th argument
.Execute , , , , , , , , , , wdReplaceAll
End With
'save the document and close Word
wrdDoc.SaveAs2 "c:\test-ok.docx"
wrdApp.Quit
'clean up
Set wrdApp = Nothing
Set wrdDoc = Nothing
PowerShell 没有 VBScript 的等效项With
陈述。代替
With wrdApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
...
End With
你可能会这样做:
$find = $wrdApp.Selection.Find
$find.ClearFormatting()
$find.Replacement.ClearFormatting()
...
或者像这样:
$wrdApp.Selection.Find | ForEach-Object {
$_.ClearFormatting()
$_.Replacement.ClearFormatting()
...
}
另外,据我所知,没有 VBScript 或 VBA 到 PowerShell 编译器。我整理了一些关于如何将 VBA 代码转换为 PowerShell https://sdb.planetcobalt.net/vba2psh.shtml, 尽管。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)