如何在vbscript中强制保存和替换 [英] How to force save and replace in vbscript

查看:24
本文介绍了如何在vbscript中强制保存和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 AccessMode 和 ConflictResolution,对 vba 来说很好.

I have been using AccessMode and ConflictResolution and it was fine for vba.

在 vbs 中

ObjWB.SaveAs myFolder & "test.xlsx",  AccessMode:=xlExclusive, ConflictResolution:=Excel.XlSaveConflictResolution.xlLocalSessionChanges 

为字符:=

如何在vbs中另存为并强制替换?

How to save as and force replace in vbs ?

推荐答案

VBScript 不支持 VB 和 VBA 的 param:=value 特性.您需要按正确的顺序提供函数参数.但是,您可以省略参数值,如果它们是可选的.它也不会定义任何 Excel 常量.您必须自己定义它们.请尝试以下操作:

VBScript doesn't support the param:=value feature of VB and VBA. You need to supply function params in their proper order. You can omit parameter values, however, if they're optional. It also won't have any of Excel's constants defined. You must define them yourself. Try the following:

Const xlExclusive = 3
Const xlLocalSessionChanges = 2

ObjWB.SaveAs myFolder & "test.xlsx", , , , , , xlExclusive, xlLocalSessionChanges

以这种方式调用函数可能会与省略参数的数量混淆,因此在单独的行中指定每个参数值通常很有用(如果您不介意额外的代码行):

Calling a function this way can get confusing with the number of omitted params, however, so it's often useful to specify each param value on its own line (if you don't mind the extra lines of code):

ObjWB.SaveAs myFolder & "test.xlsx", _    ' Filename
             , _                          ' FileFormat
             , _                          ' Password
             , _                          ' WriteResPassword
             , _                          ' ReadOnlyRecommended
             , _                          ' CreateBackup
             xlExclusive, _               ' AccessMode
             xlLocalSessionChanges        ' ConflictResolution

在 Excel 的 Visual Basic 编辑器中,您可以使用对象浏览器(快捷键 = F2)来确定 Excel 类型库定义的常量的值.

Within the Visual Basic editor in Excel you can use the Object Browser (shortcut key = F2) to determine the values for constants defined by the Excel type library.

这篇关于如何在vbscript中强制保存和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆