al.extreme
New Member
- Joined
- Nov 29, 2010
- Messages
- 15
Hello
I,m trying to shift bewteen open workbooks that I previously open with another macro and recorded the names in a tab called "menu", range I4 to I6
the name of the workbooks change each week, so I try to use a variable
I previously used it with sucess for pivot tables pvt(count), but when I try to use the same principle for workbooks, I might be missing something when declaring the variables. I get the same error
Compile error:
Invalid Qualifier
and if I change to Dim wb(2 To 4) As Workbook I get the error:
ByRef Argument mismatch
any help?
this is the code
**************
Dim wb(2 To 4) As String
Dim Count As Long
wb(2) = Worksheets("menu").Range("I4").Value
wb(3) = Worksheets("menu").Range("I5").Value
wb(4) = Worksheets("menu").Range("I6").Value
For Count = 2 To 4
If IsFileOpen(wb(Count)) Then
Windows wb(Count).Activate
Else
MsgBox ("The Workbook " & wb(Count) & " is not open, please check file and try again!")
Exit Sub
End If
PivotCheck
Application.Calculation = xlCalculationManual
Dim pvtitem As PivotItem
With ActiveSheet.PivotTables(1).PivotFields("Calendar")
On Error Resume Next
.PivotItems(DataField_1).Visible = True
On Error GoTo 0
On Error Resume Next
.PivotItems(DataField_2).Visible = True
On Error GoTo 0
On Error Resume Next
.PivotItems(DataField_3).Visible = True
On Error GoTo 0
The code goes on....
I,m trying to shift bewteen open workbooks that I previously open with another macro and recorded the names in a tab called "menu", range I4 to I6
the name of the workbooks change each week, so I try to use a variable
I previously used it with sucess for pivot tables pvt(count), but when I try to use the same principle for workbooks, I might be missing something when declaring the variables. I get the same error
Compile error:
Invalid Qualifier
and if I change to Dim wb(2 To 4) As Workbook I get the error:
ByRef Argument mismatch
any help?
this is the code
**************
Dim wb(2 To 4) As String
Dim Count As Long
wb(2) = Worksheets("menu").Range("I4").Value
wb(3) = Worksheets("menu").Range("I5").Value
wb(4) = Worksheets("menu").Range("I6").Value
For Count = 2 To 4
If IsFileOpen(wb(Count)) Then
Windows wb(Count).Activate
Else
MsgBox ("The Workbook " & wb(Count) & " is not open, please check file and try again!")
Exit Sub
End If
PivotCheck
Application.Calculation = xlCalculationManual
Dim pvtitem As PivotItem
With ActiveSheet.PivotTables(1).PivotFields("Calendar")
On Error Resume Next
.PivotItems(DataField_1).Visible = True
On Error GoTo 0
On Error Resume Next
.PivotItems(DataField_2).Visible = True
On Error GoTo 0
On Error Resume Next
.PivotItems(DataField_3).Visible = True
On Error GoTo 0
The code goes on....