2013-03-15 194 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