2016-03-30 29 views
0

Bir sınıf için aşağıdaki kodu hata ayıklamaya çalışıyorum. Hayatım boyunca her bir açıklamada neyin yanlış olduğunu göremiyorum.Nesne, VBA'daki özellik veya yöntem hatasını desteklemiyor Her döngü için

Public Sub PrintWorksheets1() 
    'declare variables and assign address to object variable 
    Dim intPrint As Integer, wkbHours As Workbook, shtCurrent As Worksheets 
    Set wkbHours = Application.Workbooks("T9-EX-E9D.xls") 
    'ask user if he or she wants to print the worksheet 
For Each shtCurrent In wkbHours 
    intPrint = _ 
     MsgBox(prompt:="Print " & shtCurrent.Name & "?", Buttons:=vbYesNo + vbExclamation) 
    If intPrint = vbYes Then  'if user wants to print 
     shtCurrent.PrintPreview 
    End If 
Next shtCurrent 
End Sub 

Etkin sayfaya ve yalnızca çalışma sayfalarına shtCurrent ayarlamayı denedim. Herhangi bir yardım büyük ölçüde takdir edilecektir!

cevap

0

Güncelleme kod: neredeyse vardı ama çalışma kitabı çalışma sayfaları arasında döngü gerekir ...

Public Sub PrintWorksheets1() 
    'declare variables and assign address to object variable 
    Dim intPrint As Integer, shtCurrent As Worksheet 
    Dim wkbHours As Workbook: Set wkbHours = Workbooks("T9-EX-E9D.xls") 
    'ask user if he or she wants to print the worksheet 
    For Each shtCurrent In wkbHours.Worksheets 
     intPrint = MsgBox(prompt:="Print " & shtCurrent.Name & "?", Buttons:=vbYesNo + vbExclamation) 
     'if user wants to print 
     If intPrint = vbYes Then shtCurrent.PrintPreview 
    Next shtCurrent 
End Sub 
+0

teşekkür ederiz! Her bir açıklama için sadece çalışma kitabı seviyesinden ziyade çalışma sayfaları seviyesine inmek gerektiğini görüyorum. –

İlgili konular