Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

Using VB Script to open, save, and close a program

$
0
0
I am trying to have VB open Excel, save the workbook (after a macro runs), then close the workbook. The catch is that I have an Adobe Report-Builder Plugin (used to pull Adobe Analytics into the worksheet) that is set to run (via macro) upon the launch of this particular workbook. It wouldnt be a problem except it has its own set of popup-prompts to save the workbook prior to exiting. Thus, when i want the workbook to close i cant use the following code because the Adobe popup/prompt takes focus
Code:

        xlWb.Save
        xlWb.Close SaveChanges=True
        xl.Quit

So I need to send an "enter" key to that active window (to click "yes" to save). So far i have this. Im not sure if the sendkey command is working correctly or whether i need to point that command to the focus/active window.

Code:

Sub RunMacro()
        Set xl          = CreateObject("Excel.application")
        Set xlWb = xl.Workbooks.Open("C:\Users\me\Documents\workbook.xlsm")
        xl.Application.Visible = True
        xl.Application.run "'workbook.xlsm'!RefreshAllReportBuilderRequests"
        WScript.Sleep 60000
        xlWb.Close
        WScript.Sleep 2000
        Set WshShell = WScript.CreateObject("WScript.Shell")
        WshShell.SendKeys "{ENTER}"
        Set xlWb = Nothing
        Set xl          = Nothing
        Set shell  = Nothing
End Sub


Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>