Shell.BrowseForFolder 权限不够

本文介绍如何使用JavaScript通过ActiveX对象打开本地文件夹选择对话框,并提供了一个示例代码。如果遇到“書き込みできません”错误,请确保IE浏览器中未禁用未标记为安全的ActiveX控件。
In javascript

var Shell = new ActiveXObject("Shell.Application");
var RetI = Shell.BrowseForFolder(0, 'フォルダ選択ダイアログ', 1);


you can open local folder explore dialog to select a folder.

But if you encounter error with "書き込みできません"

please comfirm whether スクリプトを実行しても安全だとマークされていないActiveXコントロールの初期化とスクリプトの実行 is set to "有効にする" in IE explore
Sub CATMain() Dim oDoc As Document Set oDoc = CATIA.ActiveDocument If Not TypeName(oDoc) = "ProductDocument" Then MsgBox "请先打开装配体文件!", vbCritical Exit Sub End If ' 用户参数输入框 Dim sPrefix As String, sSuffix As String Dim iStartNum As Integer, iStep As Integer Dim bOverwrite As Boolean sPrefix = InputBox("输入文件名前缀(留空忽略):", "前缀设置") sSuffix = InputBox("输入文件名后缀(留空忽略):", "后缀设置") iStartNum = CInt(InputBox("起始序号:", "序号设置", "1")) iStep = CInt(InputBox("序号步长:", "序号设置", "1")) bOverwrite = MsgBox("覆盖原文件?", vbYesNo + vbQuestion) = vbYes ' 遍历装配体组件 RenameComponents oDoc.Product.Products, sPrefix, sSuffix, iStartNum, iStep, bOverwrite MsgBox "批量重命名完成!", vbInformation End Sub ' 递归重命名函数 Sub RenameComponents(oProducts As Products, _ sPrefix As String, _ sSuffix As String, _ ByRef iCounter As Integer, _ iStep As Integer, _ bOverwrite As Boolean) Dim oProduct As Product For Each oProduct In oProducts ' 跳过隐藏文件[^1] If Not oProduct.Reference.Displayed Then GoTo NextProduct ' 处理子装配体(递归) If oProduct.Products.Count > 0 Then RenameComponents oProduct.Products, sPrefix, sSuffix, iCounter, iStep, bOverwrite End If Dim oDoc As Document Set oDoc = oProduct.Reference.Document ' 构建新文件名(含序号递增) Dim sNewName As String sNewName = sPrefix & GetOriginalName(oDoc) & sSuffix & "_" & Format(iCounter, "000") iCounter = iCounter + iStep ' 执行重命名 If bOverwrite Then oDoc.SaveAs oDoc.Path & "\" & sNewName & "." & GetExtension(oDoc) Else Dim sSavePath As String sSavePath = ChooseFolder() & "\" & sNewName & "." & GetExtension(oDoc) oDoc.SaveAs sSavePath End If NextProduct: Next End Sub ' 辅助函数:获取原始文件名 Function GetOriginalName(oDoc As Document) As String Dim sFullName As String sFullName = oDoc.Name GetOriginalName = Left(sFullName, InStrRev(sFullName, ".") - 1) End Function ' 辅助函数:获取文件扩展名 Function GetExtension(oDoc As Document) As String Select Case True Case TypeName(oDoc) = "PartDocument": GetExtension = "CATPart" Case TypeName(oDoc) = "ProductDocument": GetExtension = "CATProduct" End Select End Function ' 辅助函数:文件夹选择对话框 Function ChooseFolder() As String Dim oShell As Object Set oShell = CreateObject("Shell.Application") With oShell.BrowseForFolder(0, "选择保存目录", 0) If Not IsNull(.Self.Path) Then ChooseFolder = .Self.Path End With End Function 代码不能运行
11-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值