2016-12-14 65 views
-1

是否可以在 PowerShell中運行VB代碼?我不想從PowerShell內部調用.vbs,我想將VB代碼嵌入到PowerShell腳本中。我喜歡,90%確定你可以做到這一點,但我不知道如何以及不能得到穩定的Google結果。我只是在猜測這一點。在PowerShell中運行VB代碼

我目前在PowerShell中調用帶有參數的.vbs參數,因爲參數參數是基於執行器在運行PowerShell時所做的選擇,但我真的很想將它全部包裝到一個文件中。

目前,我用這把一個Excel工作表的第2頁到CSV:

Dim oExcel 
Set oExcel = CreateObject("Excel.Application") 
Dim oBook 
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0)) 
oBook.Worksheets(2).Activate 
oBook.SaveAs WScript.Arguments.Item(1), 6 
oBook.Close False 
oExcel.Quit 

我試圖用this from the Scripting Guy blog,但不能讓它的工作,並沒有得到回答有。

我得到這個錯誤:

Const : The term 'Const' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify 
that the path is correct and try again. 
At line:1 char:1 
+ Const xlCSV = 6 
+ ~~~~~ 
    + CategoryInfo   : ObjectNotFound: (Const:String) [],  CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

如果有人能告訴我這PowerShell代碼是如何工作的,讓我的Excel工作表(SHEET1)的第二張我喜歡這一點。

我希望答案就像我認爲的那樣簡單愚蠢。感謝您的幫助。

+0

將有助於包括相關的PowerShell的線路也 –

+0

您的代碼段是一個VBScript。看起來您的PowerShell腳本需要提供,因爲這表示PowerShell表示意外的術語。不,你不能「在PowerShell *中編寫VB腳本」,你必須調用它,並且來回傳遞數據......但這似乎是非常不必要的。只需使用PowerShell。 – gravity

+0

我的PowerShell代碼很好。其中的唯一對.vbs的引用是vb參數/調用'。\ Converter.vbs「$ Selection」「$ WorkCSV」'。如果有人知道如何讓該腳本專家的部分工作,這將解決我的問題。 – Nate

回答

相關問題