skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Monday, October 29, 2012

Transferring macros using java

Posted by Raju Gupta at 1:59 AM – 0 comments
 

Macros of excel can be executed using vbscript calling from a java file

using apachepoi and jexcel api we can read and write in excel file using this jars but to read macros we need to run vb script and this method calls vbscript and transfer macros....or other way around use component to change excel file in to xml file and then load it to your project

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
 
public class AccessMacro {
 
    private static void createAndShowGUI(){
 
        JFrame frame1 = new JFrame("Run Macro");
        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        JButton button = new JButton(" >> JavaProgrammingForums.com <<");
        // Add action listener to button
        button.addActionListener(new ActionListener() {
 
 
            public void actionPerformed(ActionEvent e) {
                // Execute when button is pressed
                try{
                Runtime.getRuntime().exec("cmd /c start runmacro.vbs");
                }catch(Exception a){
                    System.out.println("Problem opening runmacro script!");
                }
            }
        });
 
 
        frame1.getContentPane().add(button);
        frame1.pack();
        frame1.setVisible(true);
    }
 
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

Labels: Excel Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger