Dingrui‘s Blog

Data Science · Accounting & Finance · Random Thoughts

标签: VBA

A Simple Way to Call VBA Macro and Pass Arguments From R and Python

Sometimes you may encounter huge legacy VBA codes and you are so redundant to re-develop them in other languages (ie. R and Python). However, you really want to add running VBA codes in your workflow. Now there is a simple solution for R and Python. (Tested on Windows OS)

Sample VBA code

We have following macro.


Public Sub Test_Add(Arg1, Arg2) Sheets(1).Range("a1").Value = Arg1 + Arg2 End Sub

We would like to pass the 2 numbers to this macro and write the value in the excel book.

For R

Read More

Dingrui’s Useful VBA Scripts

This blog will be updated from time to time. Please check it regularly

Here are some useful VBA scripts (Macros in Excel).

You can download it through following links.

Please enable macro settings before using the following scripts.(Click this link for more information)

  1. Web Scraping Using VBA

This one calls the “IE” explorer in windows OS.(So if you are using Mac OS, please skip this one)
Please click correct button based on your location(Since chinese government blocks Google in mainland area)
It will pop up an IE window with a Google searching result page or a Baidu searching result page.

Read More