Mar 11, 2016 2016-03-11T08:335Z ##errorMethod invocation failed because System.Char does not contain a method named 'StartsWith'. There were a hundred odd errors exactly the same as the one above which i have left out for clarity.
this is my first StackOverflow question, but I will try to keep the community standards in mind..
I am running Office 2013 on Win7 Pro and PoSh v4.0. Upon execution of the subsequent script, I receive the following error: 'Method invocation failed because [System.__ComObject] does not contain a method named 'Close'.'
In keeping with the standard of presenting the shortest code that will reproduce the error, I developed the above code down from a larger automation
Powershell 4.0 and Excel 2013 | Bug | Work-a-round seemed to be getting at the same point. I followed the thread/culture solution offered by XXInvidiaXX and the same error was generated.
Problems with Excel automation in PowerShell had an answer by Roy that pointed to a timing error, but I inserted a Sleep command and tried running the open and close commands separately, both to no avail.
Any help, especially underlying theory, is greatly appreciated.
Community♦
![Method Invocation Failed Because [system.xml.xmlelement Does Not Contain A Method Named Method Invocation Failed Because [system.xml.xmlelement Does Not Contain A Method Named](/uploads/1/2/4/9/124921619/762609118.png)
BI_BadgerBI_Badger
2 Answers
Even though the arguments to
Workbook.Close()
are all optional, all the examples on MSDN provide at least one (the SaveChanges argument), leading me to believe that PowerShell does not recognize the method signature when you don't provide any arguments.You might have better luck with:
or
Substitute with
Mathias R. JessenMathias R. Jessen$true
to save any changes you may have made62k55 gold badges7171 silver badges117117 bronze badges
I tend to use a method of
Quit()
at the level of the Excel process ($xl
in this case), rather than the workbook ($wb1
).So using your code, it would be written as follows (with
$xl.Quit()
instead of $wb1.Close()
):Also be sure to run it as administrator.
MylesMyles
Not the answer you're looking for? Browse other questions tagged powershellscriptingpowershell-v4.0 or ask your own question.
Why does this PowerShell Script not work:
Error is
If I replace
by
it will work, but I'd like to know why first syntax does not work because it is illogical for me.
Ansgar Wiechers$xml.products
should be a valid XML object and thus provide the method AppendChild()
.149k1515 gold badges140140 silver badges198198 bronze badges
user310291user31029114.5k6161 gold badges208208 silver badges395395 bronze badges
2 Answers
$xml.products
does not reference the products
node itself, but the contents of the products
node. Since products
is empty, it evaluates to an empty string.To get to the
products
node you could also use:or, more specifically:
But
Mathias R. JessenMathias R. JessenSelectSingleNode()
will probably serve you just fine62k55 gold badges7171 silver badges117117 bronze badges
would work fine, but an interesting & dirty hack: given this empty node:
the script
gives a '
Method invocation failed because [System.String] does not contain a method named 'AppendChild'
' error but this:
works perfectly fine
VlandVland3,33322 gold badges2020 silver badges3434 bronze badges