Hi,
I've been trying to automate an excel file to run overnight. The file basically loops through 50 states, refreshing the data for each state via Essbase and saving the file off on the directory.
To give the lay of the land a litlte bit, I have two modules:
"mdlEssbase" contains all the Essbase connect/retrieve logic. I'm pretty sure it's a relatively standard code block that you can find on the internet.
"Module1" contains my two main subs, "SaveFile" and "Retrieval". Save File has the loop and save.as logic, Retrieval specifies all the ranges to be pulled and does the hide/unhide tab type stuff.
I came across the idea of using Windows Task Scheduler to launch a .vbs file that would in turn run my excel workbook. The VBS is below:
The sub I'm targeting is "SaveFile", which looks like this:
and a little piece of Retrieval looks like this (there are many tabs and ranges to pull):
My issue is that when using the .vbs script to run the process, the connection to essbase isn't happening. It will loop through all the other commands, like selecting a range or hiding/unhiding a sheet and saving, etc, just not the stuff contained in mdlEssbase module. However, if I just run the SaveFile sub(launching from excel, not using the vbs), it'll all work correctly.
I'm not sure what my issue is - any thoughts? Thanks!
I've been trying to automate an excel file to run overnight. The file basically loops through 50 states, refreshing the data for each state via Essbase and saving the file off on the directory.
To give the lay of the land a litlte bit, I have two modules:
"mdlEssbase" contains all the Essbase connect/retrieve logic. I'm pretty sure it's a relatively standard code block that you can find on the internet.
"Module1" contains my two main subs, "SaveFile" and "Retrieval". Save File has the loop and save.as logic, Retrieval specifies all the ranges to be pulled and does the hide/unhide tab type stuff.
I came across the idea of using Windows Task Scheduler to launch a .vbs file that would in turn run my excel workbook. The VBS is below:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
Set myxlApplication = CreateObject("Excel.Application")
myxlApplication.Visible = True
Set myWorkBook = myxlApplication.Workbooks.Open("Path & File Name.xlsm")
myWorkBook.Application.Run "Module1.SaveFile"
myxlApplication.Quit
The sub I'm targeting is "SaveFile", which looks like this:
Code:
Sub SaveFile()
Dim thefile, thepath As String
Dim State As String
Dim RngStates As Range
Set RngStates = ActiveWorkbook.Worksheets("Control").Range("$R$7:$R$57")
Call mdlEssbase.connectMe("R")
'Begin Loop
For Each cell In RngStates
ActiveWorkbook.Worksheets("Control").Range("C6") = cell.Value
State = Worksheets("Control").Range("C6")
Call Retrieval
Let thepath = "path goes here"
Let thefile = "filename goes here.xlsm"
ActiveWorkbook.SaveAs Filename:=thepath & thefile _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Next cell
MsgBox ("All States Run")
End Sub
and a little piece of Retrieval looks like this (there are many tabs and ranges to pull):
Code:
Sub Retrieval()
Sheets("PI_SF_NBAWP").Visible = True
Worksheets("PI_SF_NBAWP").Activate
Range("SF_NB_AWP_Pull").Select
Call mdlEssbase.EssbaseRetrieve
Range("SF_NB_Leakage_Pull").Select
Call mdlEssbase.EssbaseRetrieve
Range("A1").Select
My issue is that when using the .vbs script to run the process, the connection to essbase isn't happening. It will loop through all the other commands, like selecting a range or hiding/unhiding a sheet and saving, etc, just not the stuff contained in mdlEssbase module. However, if I just run the SaveFile sub(launching from excel, not using the vbs), it'll all work correctly.
I'm not sure what my issue is - any thoughts? Thanks!
Last edited by a moderator: