4
$\begingroup$

I am trying to add a copy after the active sheet.

I can add it before as follows (this question was asked before but now I need the answer to make my workflow:

Needs["NETLink`"]
InstallNET[]
excelObj=CreateCOMObject["Excel.Application"]
wb=excelObj@Workbooks@Open["~/example.xlsx"]
sheets=wb@Worksheets
sheets[1]@Copy[sheets[1]]

but I need to add it after which is the second parameter. How do I pass the active sheet as the second parameter? Tried the following without success:

sheets[1]@Copy[None(*what do I put here?*),sheets[1]]

Documentation for NETLink is so bad that it is missing very trivial things like these.

Also, what is the syntax for passing named parameters?

Here is the reference page for the Copy method.

$\endgroup$
7
  • 1
    $\begingroup$ Could you please provide a complete example of what you are trying to do? (I.e. include all the code needed to run the problematic command) Like this, it is very hard for people to try and help you, because they first have to guess how exactly you are doing things (also, copy and paste is way faster, so people are more likely to invest time to actually try to help you) $\endgroup$
    – Lukas Lang
    Jun 13, 2022 at 8:02
  • $\begingroup$ @LukasLang added the commands and reference to another question asked on the Wolfram Community. $\endgroup$
    – user13892
    Jun 13, 2022 at 12:08
  • $\begingroup$ I would have guessed that a simple sheets[1]@Copy[Null,sheets[1]] works (since Null is the default value of the Before argument), but for some reason it fails on my machine. One crazy alternative is to compile a dll on-the-fly to do the call for you, but so far I haven't managed to get the correct dll compiled from within Mathematica $\endgroup$
    – Lukas Lang
    Jun 13, 2022 at 15:32
  • 1
    $\begingroup$ I think it's Type.Missing based on this post (haven't tested it). $\endgroup$
    – Ben Izd
    Jun 13, 2022 at 17:06
  • 1
    $\begingroup$ @user13892 First LoadNETType["System.Type"] then Type`Missing. $\endgroup$
    – Ben Izd
    Jun 13, 2022 at 19:41

1 Answer 1

3
$\begingroup$

As Microsoft noted on the Type.Missing Page:

The following code example shows the use of the Missing field to invoke a method with its default arguments.

To use this in Mathematica, first load the type:

LoadNETType["System.Type"]

Then use Type`Missing as the missing argument.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.