4

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.

Ben Izd
  • 9,229
  • 1
  • 14
  • 45
user13892
  • 9,375
  • 1
  • 13
  • 41
  • 1
    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) – Lukas Lang Jun 13 '22 at 08:02
  • @LukasLang added the commands and reference to another question asked on the Wolfram Community. – user13892 Jun 13 '22 at 12:08
  • 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 – Lukas Lang Jun 13 '22 at 15:32
  • 1
    I think it's Type.Missing based on this post (haven't tested it). – Ben Izd Jun 13 '22 at 17:06
  • @BenIzd how do you get access to this type in NETLink? – user13892 Jun 13 '22 at 18:53
  • 1
    @user13892 First LoadNETType["System.Type"] then Type`Missing. – Ben Izd Jun 13 '22 at 19:41
  • @BenIzd thank you it works! If you want to provide it as an answer, I will accept it. You deserve it! – user13892 Jun 13 '22 at 21:28

1 Answers1

3

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.

Ben Izd
  • 9,229
  • 1
  • 14
  • 45