-1

I have an excel where it has a macro defined in it. I am creating a Java program to perform some actions on that particular spreadsheet. Here is the small snippet of the VB code

Sub ChangeAxis()
Attribute ChangeAxis.VB_ProcData.VB_Invoke_Func = "a\n14"
 '
 'ChangeAxis Macro
 'Keyboard Shortcut: Ctrl+a
    ActiveChart.Axes(xlValue).Select
    ActiveChart.Axes(xlValue).MaximumScale = 0.8
End Sub

Now, what i will have to do is, Open that spread Sheet, edit that macro with a specific Value( i.e 0.8 will be changed based on the scenarios of process), run the macro and then save the SpreadSheet.

Could someone suggest me how to edit the Macro using Java code. Or is there a way i can run this Macro VBscript from my Java code directly?

Community
  • 1
  • 1
Vinmee
  • 23
  • 2
  • 8
  • Java or JavaScript - which one is it? – VLAZ Sep 15 '16 at 19:46
  • I am using Java 1.8 – Vinmee Sep 15 '16 at 19:50
  • 1
    Is there a reason why you can't just change the macro to receive a parameter of 0.8 (or whatever other value you want the macro to use)? (E.g. `Sub ChangeAxis(Optional scaleValue As Double = 0.8)` (with, obviously, the `ActiveChart.Axes(xlValue).MaximumScale = 0.8` becoming `ActiveChart.Axes(xlValue).MaximumScale = scaleValue`) – YowE3K Sep 15 '16 at 20:00
  • Yes, I can consider this option as well. Can we pass a Value to Macro? – Vinmee Sep 15 '16 at 20:16
  • For e.g. you may find some advices there: http://stackoverflow.com/questions/6937777/how-to-call-a-macro-from-apache-poi-library-in-java – XemyL Sep 15 '16 at 20:50

1 Answers1

0

You will need to use a Java to COM library like JACOB : http://danadler.com/jacob/

Miner_Glitch
  • 537
  • 4
  • 16