Lỗi Subcript Out of Range (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

kscongtrinh

Thành viên mới
Tham gia
11/7/16
Bài viết
35
Được thích
1
Nhờ các anh, chị chỉ bảo, đoạn code sau nhưng sau khi chạy luôn bị lỗi scrript out of range
Mã:
Sub print_concrete_1()Dim printar
Dim printarkp
printar = Array("COVER", "LIST", "Request", "4A", "Resume", "Coordi", "Polymer", "Drill.Excavation", "Rebar", "Conc", "Graph(chart)", "Sample")
printarkp = Array("COVER", "LIST", "Request", "4A", "Resume", "Coordi", "Polymer", "Drill.Excavation", "Rebar", "Conc", "Graph(chart)", "Sample", "KP")
    If Range("BF5") <> "" Then
        Application.ScreenUpdating = False
        With Application.ThisWorkbook
        .Worksheets("Printar").PrintOut , , , , Application.Dialogs(xlDialogPrinterSetup).Show
        End With
    Else
        Application.ScreenUpdating = False
        With Application.ThisWorkbook
        .Worksheets("Printarkp").PrintOut , , , , Application.Dialogs(xlDialogPrinterSetup).Show
        End With
    End If
    Application.ScreenUpdating = True
End Sub
Cảm ơn mọi người
 
Nhờ các anh, chị chỉ bảo, đoạn code sau nhưng sau khi chạy luôn bị lỗi scrript out of range
Mã:
Sub print_concrete_1()Dim printar
Dim printarkp
printar = Array("COVER", "LIST", "Request", "4A", "Resume", "Coordi", "Polymer", "Drill.Excavation", "Rebar", "Conc", "Graph(chart)", "Sample")
printarkp = Array("COVER", "LIST", "Request", "4A", "Resume", "Coordi", "Polymer", "Drill.Excavation", "Rebar", "Conc", "Graph(chart)", "Sample", "KP")
    If Range("BF5") <> "" Then
        Application.ScreenUpdating = False
        With Application.ThisWorkbook
        .Worksheets("Printar").PrintOut , , , , Application.Dialogs(xlDialogPrinterSetup).Show
        End With
    Else
        Application.ScreenUpdating = False
        With Application.ThisWorkbook
        .Worksheets("Printarkp").PrintOut , , , , Application.Dialogs(xlDialogPrinterSetup).Show
        End With
    End If
    Application.ScreenUpdating = True
End Sub
Cảm ơn mọi người
Nó báo lỗi ở chỗ nào vậy bạn? mình đoán lỗi ở "Printar". Bạn bỏ cái " đi xem sao.
Cái
Application.ScreenUpdating = False bạn viết 1 lần thui, viết 2 lần làm chi vậy.
 
Upvote 0
PHP:
Sub print_concrete_1()
Dim printar, printarkp
printar = Array("COVER", "LIST", "Request", "4A", "Resume", "Coordi", "Polymer", "Drill.Excavation", "Rebar", "Conc", "Graph(chart)", "Sample")
printarkp = Array("COVER", "LIST", "Request", "4A", "Resume", "Coordi", "Polymer", "Drill.Excavation", "Rebar", "Conc", "Graph(chart)", "Sample", "KP")
1 If Range("BF5") <> "" Then
Application.ScreenUpdating = False
3 With Application.ThisWorkbook
.Worksheets("Printar").PrintOut , , , , Application.Dialogs(xlDialogPrinterSetup).Show
5 End With
Else
7 Application.ScreenUpdating = False
With Application.ThisWorkbook
9 .Worksheets("Printarkp").PrintOut , , , , Application.Dialogs(xlDialogPrinterSetup).Show
End With
11 End If
Application.ScreenUpdating = True
End Sub

Vì mình không có mày in, nên chỉ có những nhận xét & khuyến cáo ngoài rìa mà thôi:
Bạn có thể đánh dấu số cho các dòng lệnh (như trên là ví dụ)
Sau đó tiến hành bẫy lỗi để biết dòng lệnh nào đang sai (Nhờ hàm Erl() trong VBA)
Sau đó thay đổi trị trong ô [BF5] để thử tiếp.
Thử cho đến khi tìm ra nguyên nhân lỗi hay . . . chán thì thôi!

Còn câu này có thể là ngu ngơ: 2 Tham biến bạn đã gán trị dùng làm gì trong macro này nhỉ?
 
Upvote 0
Bạn thử đoạn sau xem:

PHP:
Sub print_concrete_1()
Dim printar, printarkp
Dim i&
printar = Array("COVER", "LIST", "Request", "4A", "Resume", "Coordi", "Polymer", "Drill.Excavation", "Rebar", "Conc", "Graph(chart)", "Sample")
printarkp = Array("COVER", "LIST", "Request", "4A", "Resume", "Coordi", "Polymer", "Drill.Excavation", "Rebar", "Conc", "Graph(chart)", "Sample", "KP")
    If Range("BF5") <> "" Then
        Application.ScreenUpdating = False
        With Application.ThisWorkbook
            For i = 0 To UBound(printar)
                .Worksheets(printar(i)).PrintOut
                '.Worksheets(Printar(i)).PrintPreview
            Next i
        End With
    Else
        Application.ScreenUpdating = False
        With Application.ThisWorkbook
            For i = 0 To UBound(printarkp)
                .Worksheets(printarkp(i)).PrintOut
'                .Worksheets(Printarkp(i)).PrintPreview
            Next i
        End With
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Vì mình không có mày in, nên chỉ có những nhận xét & khuyến cáo ngoài rìa mà thôi:

Còn câu này có thể là ngu ngơ: 2 Tham biến bạn đã gán trị dùng làm gì trong macro này nhỉ?

1/ Có thể dùng .PrintPreview để kiểm tra.
Hoặc sử dụng máy in ảo (Foxit Reader PDF, CutePDF, NitroPDF...)
2/ Chắc ý của bạn chủ topic muốn in các sheet liệt kê trong 02 tham biến đó.
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom