Excel/VBA-如果网络连接不存在,则中止脚本 [英] Excel/VBA - Abort script if network connection does not exist
本文介绍了Excel/VBA-如果网络连接不存在,则中止脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何VBA代码可查找当前的互联网连接?
Are there any VBA code to look for a present internet connection?
我有一个将在计时器上运行的代码.此代码将打开本地网络共享驱动器上的文件.我正在寻找某种 On Error Goto ErrorMessage 代码,如果它试图在未连接网络时打开文件.
I have a code that will run on a timer. This code will open a file on a local network share drive. I am looking for some type of On Error Goto ErrorMessage code if it tries to open the file when the network isn't connected.
推荐答案
您可以在要获取的共享驱动器上检查 Dir
的 Len
.
You can check the Len
of Dir
on the shared drive you're trying to get to:
Option Explicit
Sub TestForNetworkDrive()
'suppose the file we want is at Z:\cool\vba\files\file.txt
If Len(Dir("Z:\cool\vba\files\file.txt")) = 0 Then
'handle network not available issue
MsgBox ("Network share not found...")
Else
'do timer-based code here
MsgBox ("Let's get to work!")
End If
End Sub
这篇关于Excel/VBA-如果网络连接不存在,则中止脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文