2013-03-15 115 views
0
Sub Macro1() 
' 
' Macro1 Macro 
' 

' 
    Dim wn, contacts, report As Excel.Window 
    Dim windows(1 To 100) As Excel.Window 
    Dim i As Integer 

    i = 1 
    For Each wn In Application.windows 
     windows(i) = wn 
     i = i + 1 
    Next wn 

    If IsEmailValid(windows(1).Cells(1, 1)) = True Then 
     report = windows(1) 
     contacts = windows(2) 
    Else 
     contacts = windows(1) 
     report = windows(2) 
    End If 


End Sub 

你在这里看到什么错误?根据我对VBA的了解,我正在尽我所能。预先感谢您的反馈。将窗口句柄传递给变量

+0

是什么你想做什么?什么不起作用? FWIW,你声明'wn'和'contacts'是变体。 – 2013-03-15 06:16:24

回答

1
  • 你没有带正确声明的变量(wncontacts与被variant S)。
    使用Dim wn As Excel.Window, contacts As Excel.Window, report As Excel.Window
  • 你需要使用Set分配的object
    Set windows(i) = wn
  • window对象不具有Cells财产
    目前尚不清楚你实际上是想达到什么样的,但作为一个猜测你可能希望Worksheets集合(workbook),或者可能Application.Workbooks而不是Application.Windows