一、打开 开发工具->Visual Basic ,进入代码编辑区。

二、双击 ThisWorkbook ,从右侧上部选择 打开事件,并输入代码。

Private Sub Workbook_Open()Application.Visible = FalseApplication.DisplayAlerts = FalseApplication.ScreenUpdating = FalseUserForm1.Show
End Sub

三、从 插入->用户窗口,会插入界面,左侧会出现UserForm1,根据相关功能插入对应控件并修改属性(同VB)。

四、双击控件,进入对应控件的代码输入。

以选择目录对2003版excel改为2007版本excel为例:

(其中,用的dir递归循环查找,由于涉及递归中混淆dir默认目录,所以递归中的目录必须进入数组,这样才能调用深层递归)

Private Sub btnBrowser_Click()Dim fd As FileDialogDim strPath As StringSet fd = Application.FileDialog(msoFileDialogFolderPicker)If fd.Show = -1 Then '选择了文件夹strPath = fd.SelectedItems(1)ElsestrPath = ""End IftxtPath.Text = strPathSet fd = Nothing
End SubPrivate Sub btnSearch_Click()If txtPath.Text = "" ThenMsgBox ("请选择文件夹后操作!!!")Exit SubEnd IfDim strPath As StringIf Right(txtPath.Text, 1) <> "\" Then '盘符文件夹时多了一个\,统一规格strPath = txtPath.Text & "\"End IfSearchFile (strPath)lblState.Caption = "查找完成!!!"
End SubPrivate Sub SearchFile(strPath As String)Dim strFile As String, strFolder As String, n As Long, i As LongDim strHead As String, strEnd As String, a() As StringstrFile = Dir(strPath)Do While strFile <> ""lblState.Caption = strPath & strFilestrEnd = Right(strFile, Len(strFile) - InStrRev(strFile, ".")) '尾部,后缀名If strEnd = "xls" ThenstrHead = Left(strFile, InStrRev(strFile, ".") - 1) '头部Set objFS = CreateObject("Scripting.FileSystemObject")  '文件系统检查If objFS.fileExists(strPath & strHead & ".xlsx") = False Then '不存在,转换Dim wb As WorkbookSet wb = Application.Workbooks.Open(strPath & strFile)wb.SaveAs (strPath & strHead & ".xlsx")wb.CloseSet wb = NothingKill strPath & strHead & ".xls"Else '有了,两文件同时存在lstFile.AddItem strPath & strFileEnd IfEnd IfstrFile = Dir '继续向下查找DoEventsLoopstrFolder = Dir(strPath, vbDirectory)Do While strFolder <> ""If strFolder <> "." And strFolder <> ".." ThenIf GetAttr(strPath & strFolder) And vbDirectory Thenn = n + 1ReDim Preserve a(n)a(n) = strPath & strFolder & "\"lblState.Caption = strPath & strFolder & "\"End IfEnd IfstrFolder = DirDoEventsLoopFor i = 1 To nSearchFile (a(i))Next i
End SubPrivate Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)Application.Visible = TrueApplication.DisplayAlerts = TrueApplication.ScreenUpdating = TrueDim wb As Workbook, flag As Booleanflag = False '假定无其它工作薄For Each wb In Application.WorkbooksIf wb.Name <> ThisWorkbook.Name Thenflag = True '有其它工作薄End IfNextIf flag = False Then '仅本工作蔳,直接退出excel'Application.QuitEnd If
End Sub

Excel Vba快速界面设计入门相关推荐

  1. Excel.VBA 快速删除重复记录

    Excel.VBA 快速删除重复记录 日常工作中的工作表中经常会有重复记录,清除这些重复记录是一个繁琐的工作,即使在排序之后再进行手工筛选,也经常会出现遗漏,而使用VBA代码就可以快速准确地删除重复记 ...

  2. 巧用Excel VBA 快速编排考场座位

    百度文库下载地址: 学校考试考场编排软件(单年级) http://wenku.baidu.com/view/464023029ec3d5bbfc0a740f.html 学校考试考场编排软件(多年级) ...

  3. 用access做考场桌贴_巧用Excel VBA 快速编排考场座位

    百度文库下载地址: 学校考试考场编排软件(单年级) 学校考试考场编排软件(多年级) 学校考试考场编排软件(多年级,文理绲编),请联系作者索要. 更多考试管理系统下载 [摘要]科学的考场座位编排方法可以 ...

  4. 微信小程序界面设计入门课程-样式wxss中使用css课程-字体-font-style字体风格

    font-style字体风格 微信小程序交流群:111733917 | 微信小程序从0基础到就业的课程:https://edu.csdn.net/topic/huangjuhua 基础用法 font- ...

  5. 微信小程序界面设计入门课程-样式wxss中使用css课程-文本-direction 文本方向

    样式wxss中使用css课程-文本-direction 文本方向 微信小程序交流群:111733917 | 微信小程序从0基础到就业的课程:https://edu.csdn.net/topic/hua ...

  6. (转)Excel VBA 操作 Word(入门篇)

    原文地址 本文的对象是:有一定Excel VBA基础,对Word VBA还没有什么认识,想在Excel中通过VBA操作Word还有困难的人. 一.新建Word引用 需要首先创建一个对 Word App ...

  7. 微信小程序界面设计入门课程-样式wxss中使用css课程-字体-font-size字体大小

    font-size字体大小 微信小程序交流群:111733917 | 微信小程序从0基础到就业的课程:https://edu.csdn.net/topic/huangjuhua 基础语法 有能力管理文 ...

  8. java 图形界面设计,使用JPanel、JFrame 绘图,图形界面设计入门演示,各种主要绘图方法以及图片、文字插入

    那什么是JPanel?JFrame 又是什么呢?让我们先来了解一下他们的区别吧: JFrame是最底层,JPanel是置于其面上,同一个界面只有一个JFrame,一个JFrame可以放多个JPanel ...

  9. Excel VBA 快速访问 Power Query 表格数据

    1.PowerQuery 可以方便获取外部数据,并进行数据清洗,最后将结果返回到工作表中.每次刷新数据后,工作表中返回的数据的行数不是固定的. 2.在VBA中如何方便地访问PowerQuery返回的表 ...

最新文章

  1. spring整合junit测试
  2. HDU-1016 Prime Ring Problem DFS
  3. Sharepoint 2010使用手记(1)
  4. ppp在linux下的编译和安装
  5. Docker是啥?容器变革的火花?
  6. ios7以后隐藏状态栏
  7. POJ 2243:Knight Moves(双向BFS)
  8. H5实现点击图片放大功能
  9. NRF52832 PWM 占空比调整详解
  10. 整理的遥感期刊,SCI检索,3/4区居多
  11. Python基于imageio库制作gif动图
  12. python控制电脑蜂鸣器
  13. python again语句_初识Python05--if语句
  14. 字节顺序-大端/小端、big-endian/little-endian
  15. 【Hive】Hive求所在周的第一天(周一),求所在月的第一天,求所在年的第一天
  16. Redis的sorted set类型
  17. 高通再度回归,然而华为、阿里已先行一步,外媒:来不及了
  18. echarts地图文字重叠解决方案_ECharts 和百度地图的叠加示例(下)
  19. 带音符字母html表示
  20. 给360安全浏览器添加一个图片背景/主题

热门文章

  1. 通过teamviewer访问内网
  2. 集中式和分布式版本控制系统的区别
  3. 大华视频实时调用视频
  4. 极客兔兔 TensorFlow入门教程
  5. 今日新闻简报 十二条微语早报 每天一分钟 知晓天下事 3月2日
  6. 4GL+T100程序设计开发常用方法、技巧总结
  7. 新时达电梯服务器维修,常见的新时达电梯维修时问题分析
  8. 互联网快讯:极米Z6X Pro、极米H3S获用户青睐;民德电子功率半导体赛道获进展
  9. 关于appium踩坑 selenium.common.exceptions.WebDriverException: Message: An unknown server-side error(已解决)
  10. IDEA Translation插件中有道智云(有道翻译)应用ID,密钥申请教程