VBScript、GetLocale、SetLocale - 其他用途 [英] VBScript, GetLocale, SetLocale - Other uses

查看:21
本文介绍了VBScript、GetLocale、SetLocale - 其他用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:与断言相反,这个问题不是重复.我的问题被标记为 ms-word 并且提出的建议指向 ms-excel 答案,在这种情况下不适用.Word VBA != Excel VBA.

Note: Contrary to assertions, this question is not a duplicate. My question is tagged as ms-word and the suggestions made point to an ms-excel answer, which in this case does not apply. Word VBA != Excel VBA.

我需要在德国有用户生成英语 Word 2016 文档但日期是欧洲风格的德语月份和日期名称.我们需要它们以英文日期样式和名称的形式出现.

I have a need where I have users in Germany generating English language Word 2016 documents but where the dates are coming through as European styled with German language month and day names. We need them to come through as English date styles and names.

我知道内容控件​​和日期选择器,但目前还没有这个选项(将来可能会有).更改他们的本地区域设置也不是一种选择(显然是德语).由于我不会在这里讨论的原因,出于遗留原因,我们仅限于 .DOC 格式.

I know of the Content Controls and Date Picker, though that isn't an option at this time (It may be in the future). Changing their local regional settings also isn't an option (obviously it's German). For reasons I won't go into here, we are restricted to .DOC format for legacy reasons.

发生在 VBScript 函数 GetLocale 和 SetLocal 中.在 VBScript 的上下文中完美运行...

Happened across the VBScript functions GetLocale and SetLocal. Works perfectly, in the context of VBScript...

问题是我如何能够将 VBScript 引用为 DLL 并在 Office VBA 模块中使用该功能?不幸的是,它没有内置到 Office VBA 中.

Question is how might I be able to reference VBScript as a DLL and make use of that functionality in an Office VBA module? It's not built into Office VBA unfortunately.

我已经尝试从 SYsWow64 文件夹中引用 VBScript.dll,但它唯一暴露的是 VBScript_Global.GlobalObj 和 SetLocale,GetLocale 不可用(最新文档中仍然引用了它,它没有被弃用.https://msdn.microsoft.com/en-us/library/5xf99h19(v=vs.84).aspx).

I've tried referencing VBScript.dll from the SYsWow64 folder, but the only thing it exposes is VBScript_Global.GlobalObj and SetLocale, GetLocale aren't available (It is referenced in the latest documentation still, it isn't deprecated. https://msdn.microsoft.com/en-us/library/5xf99h19(v=vs.84).aspx).

任何帮助将不胜感激.

推荐答案

这就是答案,我写的.

Public Function printDateByLocale(inputDate As Date, inputlocale As String) As String

Dim codeString As String
Dim scriptControl As Object

Set scriptControl = CreateObject("MSScriptControl.ScriptControl")

codeString = "Function getDateByLocale(myDate, locale)" & vbCrLf & "SetLocale locale" & vbCrLf & "getDateByLocale = FormatDateTime(myDate, vbLongDate) End Function"

With scriptControl
    .Language = "VBScript"
    .addCode codeString
    printDateByLocale = .Run("getDateByLocale", inputDate, inputlocale)
End With

Set scriptControl = Nothing

End Function

这篇关于VBScript、GetLocale、SetLocale - 其他用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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