Getting an error `xlValues` is not defined when Cells format to the others

前端 未结 3 1542
长情又很酷
长情又很酷 2020-12-12 00:40

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.

相关标签:
3条回答
  • 2020-12-12 01:03

    try:

    ob3.Range("A1").Copy
    ob3.Range("A1").EntireRow.PasteSpecial xlPasteFormats
    
    0 讨论(0)
  • 2020-12-12 01:03

    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

    0 讨论(0)
  • 2020-12-12 01:21

    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
    
    0 讨论(0)
提交回复
热议问题