Getting an error `xlValues` is not defined when Ce

2020-02-07 07:27发布

I am trying to copy the format of an Cell say here "A1" to the all cells of the first row using VBScript,but getting an error xlValues is not defined.

CODE

  ob3.Range("A1").Copy
  ob3.Range("A1").EntireRow.PasteSpecial(xlValues) 'error here for that constants

Can you help me here?

Thanks,

3条回答
聊天终结者
2楼-- · 2020-02-07 07:50

try:

ob3.Range("A1").Copy
ob3.Range("A1").EntireRow.PasteSpecial xlPasteFormats
查看更多
手持菜刀,她持情操
3楼-- · 2020-02-07 07:57

You can find a list of constants here: http://techsupt.winbatch.com/ts/T000001033005F9.html

These are for Excel 97 but in your case (xlValues) the constant hasn't changed (-4163).

With

Const xlValues = -4163
...
ob3.Range("A1").Copy
ob3.Range("A1").EntireRow.PasteSpecial(xlValues)

you shouldn't get an error anymore

查看更多
疯言疯语
4楼-- · 2020-02-07 07:59

As VBScript does not know about Excel's constant, you'll have to define them yourself:

Const xlValues = 123 ' <-- replace 123 with the correct value for your version of Excel
查看更多
登录 后发表回答