Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2140|回复: 1

[已解决]在vba中加IF

[复制链接]
发表于 2016-7-9 12:48 | 显示全部楼层 |阅读模式
本帖最后由 759857387 于 2016-7-9 13:32 编辑

判断有无插入U盘,然后MsgBox "找不到指定u盘"
IF.rar (10.35 KB, 下载次数: 4)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-7-9 13:16 | 显示全部楼层    本楼为最佳答案   
这样?
  1. Sub test()          '没有问题
  2. Dim fs, d
  3. Set fs = CreateObject("Scripting.FileSystemObject").Drives
  4.     For Each d In fs
  5.         If d.DriveType = 1 Then
  6.             'MsgBox d.Path
  7.             i = i + 1
  8.             Cells(i, 1) = d.Path
  9.         End If
  10.         
  11.     Next
  12.     If i = 0 Then MsgBox "找不到指定U盘"
  13. End Sub
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-25 13:07 , Processed in 0.262658 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表