xuất pdf từ excel bằng vba

Liên hệ QC

lehungbx

Thành viên mới
Tham gia
19/2/19
Bài viết
18
Được thích
4
mọi người cho e hỏi e có đoạn code xuất ra file pdf của sheet1 nhưng e muốn xuất cả sheet 2,sheets3 vào cùng 1 file thì thêm câu lệnh nào ạ
Private Sub CommandButton7_Click()
'xuat file pdf Sheet1.ExportAsFixedFormat xlTypePDF, Filename:= _
"C:\phieu\" & Sheet1.Range("bg1").Value & Sheet1.Range("bj1").Value, OpenAfterPublish:=True
End Sub
 
mọi người cho e hỏi e có đoạn code xuất ra file pdf của sheet1 nhưng e muốn xuất cả sheet 2,sheets3 vào cùng 1 file thì thêm câu lệnh nào ạ
Private Sub CommandButton7_Click()
'xuat file pdf Sheet1.ExportAsFixedFormat xlTypePDF, Filename:= _
"C:\phieu\" & Sheet1.Range("bg1").Value & Sheet1.Range("bj1").Value, OpenAfterPublish:=True
End Sub
Bạn thử code sau xem được không ạ,OT chưa thử vì mấy cái ô bg1 không biết chứa cái gì :D
Mã:
Option Explicit

Sub BeTapCode()
    Dim aSheet() As Variant, i As Integer, sFile As String
    aSheet = Array("Sheet1", "Sheet2", "Sheet3")
    sFile = "C:\phieu"
    For i = 0 To UBound(aSheet)
        With Sheets(i + 1)
            .ExportAsFixedFormat xlTypePDF, Filename:=sFile & "\" & _
            .Range("bg1").Value & _
            .Range("bj1").Value, OpenAfterPublish:=True
        End With
    Next i
End Sub
 
Upvote 0
cảm ơn bạn.trong lúc vô tình thì mình đã tìm ra cách làm rồi ạ.
 
Upvote 0
Bạn thử code sau xem được không ạ,OT chưa thử vì mấy cái ô bg1 không biết chứa cái gì :D
Mã:
Option Explicit

Sub BeTapCode()
    Dim aSheet() As Variant, i As Integer, sFile As String
    aSheet = Array("Sheet1", "Sheet2", "Sheet3")
    sFile = "C:\phieu"
    For i = 0 To UBound(aSheet)
        With Sheets(i + 1)
            .ExportAsFixedFormat xlTypePDF, Filename:=sFile & "\" & _
            .Range("bg1").Value & _
            .Range("bj1").Value, OpenAfterPublish:=True
        End With
    Next i
End Sub
Theo câu lệnh mà suy ra thì ô đó chứa tên file bạn à!
 
Upvote 0
Web KT
Back
Top Bottom