Question Tester un vba scripte

Plus d'informations
il y a 8 ans 7 mois #20706 par arnold
Tester un vba scripte a été créé par arnold
Bonjour,

Comment utiliser un vba avec powershell?:

[code:1]cls

$xl = New-Object -ComObject Excel.Application
$xl.Visible = $false # $true
$xl.DisplayAlerts = $false

$workbook = $xl.Workbooks.Open(\"c:\..\Test-VBA\test-vba.xlsx\"«»)
$xlmodule = $workbook.VBProject.VBComponents.Add(1)

$code = @\"
sub test()
msgbox \"Inside the macro\"
end sub
\"@

$xlmodule.CodeModule.AddFromString($code)
$xlmodule.SaveAs(\"c:\..\Test-VBA\test-vba.xlsx\"«»)
$workbook.quit[/code:1]

la reponse a etais:

You cannot call a method on a null-valued expression.
At C:\..\Test-VBA\Inside-the-macro.ps1:18 char:35
+ $xlmodule.CodeModule.AddFromString <<<< ($code)
+ CategoryInfo : InvalidOperation: (AddFromString:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\..\Test-VBA\Inside-the-macro.ps1:19 char:17
+ $xlmodule.saveas <<<< (\"c:\..\Test-VBA\test-vba.xlsx\")
+ CategoryInfo : InvalidOperation: (saveas:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull


Merci pour votre aide.
@r

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.062 secondes
Propulsé par Kunena