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

[RESOLVED] Message box if error

$
0
0
Hi Folks,

New to the forum. Very familiar with excel VBA but new to VBS.

I've created a code that activates and excel VBA macro. However it's reliant on me being connected to a network (which isn't always possible)

I'd like to add in an error code if the vbs can't access the workbook. If that error occurs, I'd like a message box that gives me the option to abort the script.

Here's my code:
Code:

Option Explicit

Dim xlApp, xlBook

Set xlApp = CreateObject("Excel.Application")
'~~> Change Path here
Set xlBook = xlApp.Workbooks.Open("\\network.grp\basfap\BS-HBA\ROPA\Admin_stuff\BACK UP.xlsm", 0, True)
'This is the network path. If there's an error I'd like the message box stating something along the lines of "You're not connected to the network" with an "abort" button that exits the script.
xlApp.Run "CopyMyFolder"
xlBook.Close
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing

 msgbox"BACK UP IS COMPLETE", 0+64, "Back up from Network to local drive"

I look forward to your replies.

Viewing all articles
Browse latest Browse all 686

Trending Articles



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