0
votes

I have a piece of R code in my shiny application that basically triggers a shell script that runs a macro in a excel:

path_to_vbs_file = "www/Macro_Trigger.vbs"
shell(shQuote(normalizePath(path_to_vbs_file)), "cscript", flag = "//nologo")

The .vbs code is:

Option Explicit

ExcelMacroExample

Sub ExcelMacroExample() 

  Dim xlApp 
  Dim xlBook 
  Dim fso
  Dim curDir

  Set xlApp = CreateObject("Excel.Application") 
  Set fso = CreateObject("Scripting.FileSystemObject")
  curDir = fso.GetParentFolderName(wscript.ScriptFullName) 
  Set xlBook = xlApp.Workbooks.Open(curDir & "\KPI_Report.xlsm", 0, False) 
  xlApp.Application.Visible = False
  xlApp.DisplayAlerts = False
  xlApp.Run "ConvertTextToNumber"
  xlApp.ActiveWorkbook.SaveAs curDir & "\KPI_Report.xlsm"

  xlApp.ActiveWorkbook.Close
  xlApp.Quit

  Set xlBook = Nothing 
  Set xlApp = Nothing 

End Sub 

The code works fine on local Windows OS but fails on shinyapps.io server. I tried using system command instead of shell:

path_to_vbs_file = "www/Macro_Trigger.vbs"
system(shQuote(normalizePath(path_to_vbs_file)), intern = FALSE)

But that doesn't help :(

1
I suspect that vbs code won't run on shinyapps.io as the server runs a Linux operation system. - Xiongbing Jin
Thanks for the response. Is there any alternate way that I can achieve my objective? - Racharla Achyuth Reddy
I think you'll need to use RExcel or something similar to implement the VBS code functions in R. - Xiongbing Jin

1 Answers

0
votes

shinyapps.io runs Linux, so executing a VBS script is not going work, unfortunately. My suggestion would be to port your Excel macros to pure R code.