如何使Excel UserAction独立于语言。 [英] How to get Excel UserAction Independent of Language.

查看:81
本文介绍了如何使Excel UserAction独立于语言。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


Here我的问题是,在代码中我们从commandBar获取UserAction。 Commandbar包含UndoAction,我们从中获取Undo  Object,我们正在获取动作。我们在代码中使用了这个useraction,并根据LastUseraction确定了一些基于
的操作。但问题来自于excel语言不是英语(例如:中文)。所以lastUseraction将以中文显示,我们的代码将无法正常工作。



问题: -



1.一个问题是从CommandBar获取Undo ComObject。


< p style ="padding-right:0px; font-size:14px; line-height:inherit; font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; vertical-align: baseline; list-style-type:none; color:#2a2a2a">
Soln: - 我发现我们可以通过ID找到它。对于Undo Id是128。



2: - 需要用英语获取UndoOperation。例如: - 如果用户已完成过滤,则在撤消操作中它应为"过滤器"。



当我们有中文时,UndoOpeartion会出现"中文"。



有没有办法获得操作按ID。就像我们为Undo Comobject获取它一样。

解决方案

T,

Re: 在英语中获取最后撤消操作



除了创建中文与英文的两列交叉引用列表之外,我认为不能这样做。

如果有任何帮助,Application.Undo方法将撤消用户采取的最后一个操作。

注意在MS帮助...

"此方法仅撤消用户在运行宏之前所采取的最后一个操作,并且它必须是宏中的第一行。")

'---

  Application.Undo

  Msgbox"不要那样做",vbExclamation," tinkesh"

'---

要获取可用的撤消命令列表,以下代码可能有效对于你。

(请注意,在Excel版本 xl2010之后,MS已经削弱了对命令栏的访问权限)



Sub WhatDidIDo()

  Dim objCtrl   作为CommandBarControl

  Dim objTempBar As CommandBar

 昏暗的arrList() 作为字符串

  Dim lngCount  如长龙$
  Dim lngItem   作为Long



 '撤消控制权b
 设置objCtrl = Application.CommandBars(" Formatting")。FindControl(ID:= 128)

 '如果缺少撤消控件,请创建一个临时CommandBar

  ;如果objCtrl Is Nothing则为
    设置objTempBar = Application.CommandBars.Add

    设置objCtrl = objTempBar.Controls.Add(ID:= 128)

 结束如果是
 '列表是1基于。

  lngCount = objCtrl.ListCount

  ReDim arrList(1到lngCount,1比1)

 '将可用项添加到数组中$
 对于lngItem = 1到lngCount

      arrList(lngItem,1)= objCtrl.List(lngItem)

 下一个'lngItem

 '填充列"C"在包含数组内容的活动电子表格中。

 范围(单元格(5,3),单元格(4 + lngCount,3))。值= arrList()

 如果Not objTempBar Nothing那么objTempBar.Delete

 设置objTempBar = Nothing

 设置objCtrl = Nothing

End Sub



'---
$
Jim Cone

美国俄勒冈州波特兰市
https://goo.gl/IUQUN2(Dropbox)

(免费和商业excel插件和工作簿)

Here My problem is, In code We are getting UserAction from the commandBar. Commandbar contains the UndoAction from which we are getting the Undo  Object and we are getting the action.This useraction we are using in our code and decide some operation based on the LastUseraction. But the problem comes when the excel language is Other than English(Ex:-Chinese). So the lastUseraction will come in Chinese and our code will not work as expected.

Problems:-

1. One Problem is in getting the Undo ComObject from the CommandBar.

Soln:- I found out that we can find it by ID. For Undo Id is 128.

2:-Need to get UndoOperation in English. Ex:- If User has done filter then in Undo Operation it should come as "Filter".

When we have Chinese then UndoOpeartion comes in "Chinese".

Is there a way to get the operation by ID. Just like we are getting it for Undo Comobject.

解决方案

T,
Re:  get last undo action in english

Other than creating a two column cross reference list in Chinese vs. English, I don't think it can be done.
The Application.Undo method will undo the last action taken by the user, if that is any help.
Note in MS help...
"This method undoes only the last action taken by the user before running the macro, and it must be the first line in the macro.")
'---
  Application.Undo
  Msgbox "Don't do that", vbExclamation, "tinkesh"
'---
To get a list of available undo commands, the following code might work for you.
(note that in Excel versions coming after xl2010, MS has crippled access to the command bars)

Sub WhatDidIDo()
  Dim objCtrl    As CommandBarControl
  Dim objTempBar As CommandBar
  Dim arrList()  As String
  Dim lngCount   As Long
  Dim lngItem    As Long

 'Undo Control
  Set objCtrl = Application.CommandBars("Formatting").FindControl(ID:=128)
 'If undo control is missing, create a temp CommandBar
  If objCtrl Is Nothing Then
     Set objTempBar = Application.CommandBars.Add
     Set objCtrl = objTempBar.Controls.Add(ID:=128)
  End If
 'The List is 1 based.
  lngCount = objCtrl.ListCount
  ReDim arrList(1 To lngCount, 1 To 1)
 'Adds the available items into the Array
  For lngItem = 1 To lngCount
      arrList(lngItem, 1) = objCtrl.List(lngItem)
  Next ' lngItem
 'Fills Column "C" on the active spreadsheet with the array contents.
  Range(Cells(5, 3), Cells(4 + lngCount, 3)).Value = arrList()
  If Not objTempBar Is Nothing Then objTempBar.Delete
  Set objTempBar = Nothing
  Set objCtrl = Nothing
End Sub

'---
Jim Cone
Portland, Oregon USA
https://goo.gl/IUQUN2 (Dropbox)
(free & commercial excel add-ins & workbooks)


这篇关于如何使Excel UserAction独立于语言。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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