The With statement in the VBS code, how expressed in PowerShell

前端 未结 1 1657
野趣味
野趣味 2021-01-28 21:41

Is there a software or tool that can quickly convert VBS code into PowerShell code?

In addition, I want to know, the following With statement in the VBS cod

1条回答
  •  隐瞒了意图╮
    2021-01-28 22:15

    PowerShell doesn't have an equivalent for VBScript's With statement. Instead of

    With wrdApp.Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        ...
    End With
    

    you'd probably do something like this:

    $find = $wrdApp.Selection.Find
    $find.ClearFormatting()
    $find.Replacement.ClearFormatting()
    ...
    

    or like this:

    $wrdApp.Selection.Find | ForEach-Object {
        $_.ClearFormatting()
        $_.Replacement.ClearFormatting()
        ...
    }
    

    Also, to my knowledge there is no VBScript or VBA to PowerShell compiler. I put together some notes on how to translate VBA code to PowerShell, though.

    0 讨论(0)
提交回复
热议问题