Workbook activate old versus new version of excel

时间:2018-06-18 11:41:43

标签: excel vba excel-vba

I had to use very old macro written by former employees They wrote the code in 2009 and used it on different windows version until windows 7 (and the excel version evolved accordingly).

Now, I try to launch the macro on excel 2016 / windows 10.

I always get an error with the following code:

Wb_Template.Sheets("data1").Activate
Call data1_traitement_donnees

and the sub:

 If Sheets("data1").Cells(i, 1).Value <> Sheets("data1").Cells(i - 1, 1).Value Then...

I always need to add

Wb_Template.

Before Sheet("data1")... or I get an error message. Everything was working fine before. IS there a modification of this kind of code interpretation?

1 个答案:

答案 0 :(得分:1)

在Excel 2013中;我用这种方式:

'Declare your workbook
Dim wb As Workbook
Set wb = ThisWorkbook

'Declare all your worksheet
Dim sh_test As Worksheet
Set sh_test = wb.Worksheets("Sheet1")


If sh_test.Cells(i, 2).Value = "20040155" Then ...

您不需要使用激活