Sorry - my assumption is that anyone automating Excel using anything other than Excel Macros has a higher level understanding of coding.
The first result for "passing variable to excel from powershell"
Example:
$xlApp = New-Object -ComObject "Excel.Application"
$xlApp.Workbooks.Open("C:\Users\MacroMan\Documents\MyMacroWorkbook.xlsm")
$returnValue = $xlApp.Run("'MyMacroWorkbook.xlsm'!GenerateString", 6)
In Excel:
Public Function GenerateString(strLength As Integer) As String
GenerateString = Left("FOOBAR_SOMETHING", strLength)
End Function
Since you want to pass a string
StringVariable = "WhatEverItIsThatYouWantToPAssToExcel"
$xlApp = New-Object -ComObject "Excel.Application"
$xlApp.Workbooks.Open("C:\Users\MacroMan\Documents\MyMacroWorkbook.xlsm")
$xlApp.Run "'MyMacroWorkbook.xlsm'!GetString", StringVariable
In Excel:
'Ooops!
Public Sub GetString(strVar As String)
DoSomethingMacro strVar
End Sub
Bookmarks