WordVBA函数:删除所有的VBA组件
wptr33 2024-12-09 18:01 24 浏览
在备份后,可以导入相应代码。
主要用于代码在不同电脑中转移,以及分享代码。
这个包括多个函数组,具体如下:
Private Sub 导入所有的VBA组件()
On Error GoTo ErrorHandler
Dim strPath As String
strPath = SelectedTheFolder(strIniPath)
If strPath = "" Then Exit Sub
Dim objDic As Variant
objDic = FileFullNamesInFolder(strPath)
If IsEmpty(objDic) Then Exit Sub
Dim strName As Variant
Dim strFileName As String
Dim strFileFullName As String
Dim strFileShortName As String
Dim strExtend As String
Dim strExisted As String
strExisted = ExistedThreeComponentsObjectsNames()
For Each strName In objDic
strFileFullName = strName
strFileName = Replace(strName, strPath, "")
strFileShortName = Split(strFileName, ".")(0)
strExtend = Split(strFileName, ".")(1)
' 排除 LibCore 和 ThisDocument 组件,这是手工导入
If strFileShortName <> "LibCore" And strFileShortName <> "ThisDocument" And strExtend <> "frx" Then
If InStr(1, strExisted, "|" & strFileShortName & "|") > 0 Then
Select Case MsgBox("当前已经存在名称为:" & strFileName & " 的组件,是否要覆盖?", vbYesNoCancel + vbDefaultButton2)
Case vbYes
RemoveVBComponent strFileShortName
Application.VBE.ActiveVBProject.VBComponents.Import strFileFullName
Case vbNo
On Error Resume Next
Application.VBE.ActiveVBProject.VBComponents(strFileShortName).Name = "Pre_" & strFileShortName
Application.VBE.ActiveVBProject.VBComponents.Import strFileFullName
On Error GoTo ErrorHandler
Case vbCancel
' 取消操作,继续下一个组件
End Select
Else
Application.VBE.ActiveVBProject.VBComponents.Import strFileFullName
End If
End If
Next
MsgBox "所有组件已成功导入!", vbInformation, "提示"
Exit Sub
ErrorHandler:
MsgBox "导入组件时发生错误:" & Err.Description, vbExclamation, "错误"
End Sub
' 获取当前 VBA 工程中所有模块、类和表单的名称,主要这三类!
Private Function ExistedThreeComponentsObjectsNames() As String
Dim objVBComponent As VBComponent
Dim strAllVBComponentName As String
strAllVBComponentName = "|"
For Each objVBComponent In Application.VBE.ActiveVBProject.VBComponents
Select Case objVBComponent.Type
Case vbext_ct_StdModule, vbext_ct_ClassModule, vbext_ct_MSForm
strAllVBComponentName = strAllVBComponentName & objVBComponent.Name & "|"
End Select
Next
ExistedThreeComponentsObjectsNames = strAllVBComponentName
End Function
' 删除指定名称的 VBA 组件
Private Sub RemoveVBComponent(strVBComponentName As String)
On Error Resume Next
Dim objVBComponent As VBComponent
Set objVBComponent = Application.VBE.ActiveVBProject.VBComponents(strVBComponentName)
If Not objVBComponent Is Nothing Then
Application.VBE.ActiveVBProject.VBComponents.Remove objVBComponent
End If
On Error GoTo 0
End Sub
' 选择文件夹并返回路径
Public Function SelectedTheFolder(Optional strInitialFileName As String = "D:\") As String
Dim strFolder As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.InitialFileName = strInitialFileName
.Title = "选择一个文件夹:"
If .Show <> -1 Then Exit Function
strFolder = .SelectedItems(1)
End With
SelectedTheFolder = strFolder & Application.PathSeparator
End Function
相关推荐
- Flutter状态管理之Provider数据共享的底层实现
-
#头条创作挑战赛#简介高级的Flutter工程师往往都是从最简单的架构开始研究学习,今天给大家带来的是Flutter中比较重要的状态管理框架Provider,也是每位Flutter开发者必学的框架。P...
- flutter软件开发笔记17-isolate的机制作用
-
这个isolate,相当于其他编程中的线程,并行处理一些事件,让程序更加高效。用厨房做菜的比喻帮你理解Isolate,附完整可运行的代码示例:一isolate的比喻解释假设你是一个主厨(主Isol...
- 七爪源码:如何使用 SQLite 数据库在 Flutter 中保存大数据
-
SQLite是一个开源、零配置、自包含、独立的事务关系数据库引擎,旨在嵌入到应用程序中。sqfliteFlutter的SQLite插件。支持iOS、Android和MacOS。支持事务...
- Flutter 实现多语言
-
本文同步本人掘金平台的文章:https://juejin.cn/post/7164571616314130469我们在处理跨国业务、跨地区(比如港澳台)业务的时候,需要针对当地的语言来做兼容。所以,我...
- 开始第一个Flet应用
-
Flet是基于Flutter的UI框架,但是我们不需要熟悉Flutter,也不需要会前端,只要具备Python面向对象编程基础就可以了。当然我本人是不会Flutter的,所以也没法对比Flet和Flu...
- 《史记微软UI框架轮回本纪》
-
微软者,乃美地西雅图之枭雄,曾持Windows以令诸侯。自庚午(1990)以降,数易UI之术,然其UI之框架兴也勃焉,其亡也忽焉。太史公观其轮回之迹,未尝不掷笔长叹:天命固难测,然微软UI之败,岂非自...
- Android中的数据库和本地存储在Flutter中是怎样实现的
-
如何使用SharedPreferences?在Android中,你可以使用SharedPreferencesAPI来存储少量的键值对。在Flutter中,使用Shared_Pref...
- Flutter——输入部件
-
上一节介绍了文本部件,用于显示文本。但是在我们进行日常软件开发过程中,经常是需要获取用户键入的内容,比如用户名、密码、性别、喜好等等。...
- 我用VS Code 开发工具来开发 自己的 Flutter 应用 工具快而轻
-
本文将与你一起回顾如何在VSCode里进行Flutter应用的开发。1.安装和配置根据编辑工具设定的指引来安装Dart和Flutter扩展(也叫做插件)。1.1更新扩展程序...
- Flutter 结合 Dio 使用
-
#头条创作挑战赛#上一篇文章...
- Flutter——路由
-
路由(Route)在移动开发中通常指页面(Page),这跟Web开发中单页应用的Route概念意义是相同的,Route在Android中通常指一个Activity,在iOS中指一个...
- Flutter 实战经验(五):在 VS Code 里开发 Flutter 应用
-
本文将与你一起回顾如何在VSCode里进行Flutter应用的开发。1.安装和配置根据编辑工具设定的指引来安装Dart和Flutter扩展(也叫做插件)。1.1更新扩展程序扩...
- Flutter 2 的Windows 开发试验
-
刚安装了flutter2.1dev版本,测试下很感觉兴趣的Windows开发当前flutter环境为(flutterdoctor):Doctorsummary(toseeallde...
- 基于flutter/dart仿抖音app实例
-
简介flutter_tiktok项目是基于flutter+dart+fijkplayer等技术开发的仿抖音短视频app实例。https://github.com/mjl0602/flutter_tik...
- 一周热门
-
-
C# 13 和 .NET 9 全知道 :13 使用 ASP.NET Core 构建网站 (1)
-
因果推断Matching方式实现代码 因果推断模型
-
git pull命令使用实例 git pull--rebase
-
git pull 和git fetch 命令分别有什么作用?二者有什么区别?
-
面试官:git pull是哪两个指令的组合?
-
git 执行pull错误如何撤销 git pull fail
-
git fetch 和git pull 的异同 git中fetch和pull的区别
-
git pull 之后本地代码被覆盖 解决方案
-
还可以这样玩?Git基本原理及各种骚操作,涨知识了
-
git命令之pull git.pull
-
- 最近发表
- 标签列表
-
- git pull (33)
- git fetch (35)
- mysql insert (35)
- mysql distinct (37)
- concat_ws (36)
- java continue (36)
- jenkins官网 (37)
- mysql 子查询 (37)
- python元组 (33)
- mysql max (33)
- vba instr (33)
- mybatis 分页 (35)
- vba split (37)
- redis watch (34)
- python list sort (37)
- nvarchar2 (34)
- mysql not null (36)
- hmset (35)
- python telnet (35)
- python readlines() 方法 (36)
- munmap (35)
- docker network create (35)
- redis 集合 (37)
- python sftp (37)
- setpriority (34)