ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 6532|回复: 14

[求助]VBA版本检测控制问题。

[复制链接]

TA的精华主题

TA的得分主题

发表于 2006-10-31 11:45 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

举个例子,为了控制VBA程序的最新版本,我会把最新vba程序(该程序中有版本的信息)放在A计算机上(当作服务器),同时B计算机也有VBA程序(直接提供给用户使用)。问题是:如何在B计算机上的程序每当启用宏时先到A计算机上读取相应的VBA程序的版本信息,把读到的版本信息与B计算机上的vba程序进行比较来判断b计算机上使用的vba程序是否为最新的?

以上,请教各位高手,如何实现呢?谢谢!

TA的精华主题

TA的得分主题

发表于 2006-10-31 11:59 | 显示全部楼层
在a计算机上放一个文件,把版本信息放在这个文件中。b计算机可以访问这个文件,从而可以知道最新的版本了。

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-10-31 17:44 | 显示全部楼层
QUOTE:
以下是引用yhdcxy在2006-10-31 11:59:46的发言:
在a计算机上放一个文件,把版本信息放在这个文件中。b计算机可以访问这个文件,从而可以知道最新的版本了。

原理我也清楚呀,可能否写一段代码验证一下呢,谢谢!

TA的精华主题

TA的得分主题

发表于 2006-10-31 19:54 | 显示全部楼层

試試 使用 Dsofile.dll

在A 計算機上

'

' Set reference to DSO OLE Document Properties Reader 2.0
'
Sub MSOffice_DocumentProperties_DSO()

Dim FileName As String
Dim DSO As DSOFile.OleDocumentProperties
Set DSO = New DSOFile.OleDocumentProperties
FileName = "D:\Test.xls"

DSO.Open sfilename:=FileName
DSO.CustomProperties.Add "VBA Version", "1.01"
DSO.Save

'DSO.CustomProperties.Item("VBA Version").Value = "1.1"   'Update Ver

'DSO.Save

DSO.Close

End Sub

在B 計算機上

'

' Set reference to DSO OLE Document Properties Reader 2.0
'
Sub MSOffice_DocumentProperties_DSO()
Dim FileName As String
Dim VBAVer As String
Dim DSO As DSOFile.OleDocumentProperties
Set DSO = New DSOFile.OleDocumentProperties
FileName = "\\yourNetworkPc\file.xls"
DSO.Open sfilename:=FileName
VBAVer = DSO.CustomProperties.Item("VBA Version").Value

' You program

' Debug.Print VBAVer


DSO.Close
End Sub
'

Microsoft Developer Support OLE File Property Reader 2.0 Sample 下載

Ref: 使用 OLE File Property Reader 2.0 閱讀 / 更改 MS Office 文件資料

TA的精华主题

TA的得分主题

发表于 2006-10-31 20:15 | 显示全部楼层

楼主从精英俱乐部跑到这边来了嗦!

我考虑不一定要文本文件,可以试试工簿之间引用数据(也就是B机工作簿中某个单元格=A机工作簿的某个单元格),我没有网络,无法测试,不一定行得通哈。

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-10-31 20:37 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
QUOTE:
以下是引用lotustower在2006-10-31 19:54:50的发言:

試試 使用 Dsofile.dll

在A 計算機上

'

' Set reference to DSO OLE Document Properties Reader 2.0
'
Sub MSOffice_DocumentProperties_DSO()

Dim FileName As String
Dim DSO As DSOFile.OleDocumentProperties
Set DSO = New DSOFile.OleDocumentProperties
FileName = "D:\Test.xls"

DSO.Open sfilename:=FileName
DSO.CustomProperties.Add "VBA Version", "1.01"
DSO.Save

'DSO.CustomProperties.Item("VBA Version").Value = "1.1"   'Update Ver

'DSO.Save

DSO.Close

End Sub

在B 計算機上

'

' Set reference to DSO OLE Document Properties Reader 2.0
'
Sub MSOffice_DocumentProperties_DSO()
Dim FileName As String
Dim VBAVer As String
Dim DSO As DSOFile.OleDocumentProperties
Set DSO = New DSOFile.OleDocumentProperties
FileName = "\\yourNetworkPc\file.xls"
DSO.Open sfilename:=FileName
VBAVer = DSO.CustomProperties.Item("VBA Version").Value

' You program

' Debug.Print VBAVer


DSO.Close
End Sub
'

Microsoft Developer Support OLE File Property Reader 2.0 Sample 下載

Ref: 使用 OLE File Property Reader 2.0 閱讀 / 更改 MS Office 文件資料

谢谢lotustower及时提供的代码及资料!我明天晚上测试一下(因为明天白天工作安排比较紧张,没有时间),谢谢!

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-10-31 20:38 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
QUOTE:
以下是引用xq1234在2006-10-31 20:15:24的发言:

楼主从精英俱乐部跑到这边来了嗦!

我考虑不一定要文本文件,可以试试工簿之间引用数据(也就是B机工作簿中某个单元格=A机工作簿的某个单元格),我没有网络,无法测试,不一定行得通哈。

谢谢提供方法,呵呵……

TA的精华主题

TA的得分主题

发表于 2006-11-1 12:41 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

如果不用Dsofile.dll的话,VBA也提供了CustomeDocumentProperties的Add方法.

A电脑上放

Sub UpdateVersion(strVersion As String)
    ThisWorkbook.CustomDocumentProperties.Add "VBA Verison", False, msoPropertyTypeString, strVersion
End Sub

B电脑上放

Function GetVersion(strName As String) As String
    Dim FileName As String
    Dim pptVer As DocumentProperty
   
    FileName = "\\yourNetworkPc\file.xls"
    Workbooks.Open FileName
    For Each pptVer In ActiveWorkbook.CustomDocumentProperties
        If pptVer.Name = strName Then
            GetVersion = ActiveWorkbook.CustomDocumentProperties(pptVer.Name)
            Exit For
        End If
    Next
    ActiveWorkbook.Close
End Function

然后调用

Sub mmm()
    MsgBox GetVersion("VBA Version")
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-11-2 15:33 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
QUOTE:
以下是引用winland在2006-11-1 12:41:30的发言:

如果不用Dsofile.dll的话,VBA也提供了CustomeDocumentProperties的Add方法.

A电脑上放

Sub UpdateVersion(strVersion As String)
    ThisWorkbook.CustomDocumentProperties.Add "VBA Verison", False, msoPropertyTypeString, strVersion
End Sub

B电脑上放

Function GetVersion(strName As String) As String
    Dim FileName As String
    Dim pptVer As DocumentProperty
   
    FileName = "\\yourNetworkPc\file.xls"
    Workbooks.Open FileName
    For Each pptVer In ActiveWorkbook.CustomDocumentProperties
        If pptVer.Name = strName Then
            GetVersion = ActiveWorkbook.CustomDocumentProperties(pptVer.Name)
            Exit For
        End If
    Next
    ActiveWorkbook.Close
End Function

然后调用

Sub mmm()
    MsgBox GetVersion("VBA Version")
End Sub

不好意思,winland,我在测试时发现无法打开工作簿的问题,能否帮忙解决一下呢?谢谢!


[此贴子已经被作者于2006-11-2 15:33:40编辑过]
bXqcEuFS.jpg

TA的精华主题

TA的得分主题

发表于 2006-11-2 20:01 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

FileName应该赋给它正确的完整的路径和文件名.

像你输入的"\\WANGNR\file.xls"好像不对吧.至少还应有个目录(WANGNR是服务器的主机名).

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

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-19 09:27 , Processed in 0.048603 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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