code chuyển trang 1 thành file PDF (1 người xem)

Liên hệ QC

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

Tường_Vi

Thành viên tiêu biểu
Tham gia
19/4/10
Bài viết
482
Được thích
121
Nghề nghiệp
Luôn tìm kiếm một vị trí tốt hơn
Em xin hỏi code nào chuyển sheet1.Page1 (trang 1 của sheet 1) thành 1 file PDF có tên là Test001 không?

Sau đó mình sẽ gửi mail File Test001 đến 1 hoặc nhiều địa chỉ mail cho trước
(mail gửi bằng MO Outlook 2007)

Về đoạn code gửi mail 1 sheet excel em sưu tầm được code này

PHP:
Sub EmailWithOutlook()
     'Variable declaration
    Dim oApp As Object, _
    oMail As Object, _
    WB As Workbook, _
    FileName As String
     
     'Turn off screen updating
    Application.ScreenUpdating = False
     
     'Make a copy of the active sheet and save it to
     'a temporary file
    ActiveSheet.Copy
    Set WB = ActiveWorkbook
    FileName = "Test_" & Trim(ActiveSheet.Name) & ".xls"
    On Error Resume Next
    Kill "C:\" & FileName
    On Error GoTo 0
    WB.SaveAs FileName:="C:" & FileName
     
     'Create and show the outlook mail item
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItem(0)
    With oMail
    
         'Uncomment the line below to hard code a recipient
         .To = Sheet1.Range("k3") ' gui dia chi mail toi nhung nguoi tai cell K3
         'Uncomment the line below to hard code a subject
         .Subject = "Test " & Sheet1.Range("K2") ' tao ten file 
        .Attachments.Add WB.FullName
        .Display
    End With
     
     'Delete the temporary file
    WB.ChangeFileAccess Mode:=xlReadOnly
    Kill WB.FullName
    WB.Close SaveChanges:=False
     
     'Restore screen updating and release Outlook
    Application.ScreenUpdating = True
    Set oMail = Nothing
    Set oApp = Nothing
End Sub
 
Lần chỉnh sửa cuối:
  1. Open Microsoft Office Excel and go to File->Open, browse for the spreadsheet you want converted to PDF and open it
  2. Go to File->Print and in the Printer section select novaPDF
  3. Before creating the PDF file you can adjust novaPDF’s settings by using the Properties button (for instance adding document information, using auto-save options, embedding fonts, adjusting page size and resolution)
  4. In the Print what section, you can choose to print the active worksheet (Active sheet), certain areas of the worksheet (Selection) or the Entire workbook
  5. Click on OK and choose a location where you want the PDF file saved. After the PDF is created it will be automatically opened in the default PDF viewer (this action is set by default but it can be configured too using novaPDF’s Properties window)
excel2003-pdf.png

Printing an entire Excel workbook to a single PDF file

By default, Excel will print only the active sheet(s), so if you want to print the entire workbook to a single PDF file you have to follow these steps:
  1. Open Microsoft Office Excel and go to Office Button->Open, browse for the workbook you want converted to PDF and open it
  2. Right-click the tab for any of the sheets you have in the workspace and choose the Select all Sheetsoption
  3. Go to Office Button->Print and select Entire workbook in the Print what section
  4. Make sure novaPDF is selected in the Printer name section and click OK to create the PDF file
  5. novaPDF will ask you where to save the PDF and it will open the PDF when it's created
Em đã download NovaPDF
http://www.novapdf.com/en/download.html

v
à đã tạo được file PDF

PHP:
Sub Macro7()'' Macro7 Macro' Tao File PDF'


 Application.ActivePrinter = "novaPDF Pro v7 on NVP7:"   
 ExecuteExcel4Macro _        
"PRINT(2,1,1,1,,,,,,,,2,""novaPDF Pro v7 on NVP7:"",,,,FALSE)"

End Sub

Trong quá trình record em có đặt tên file nhưng không thấy code và làm sao em có thể gửi mail được file Test001 này đi tới một địa chỉ ví dự yeulachet@yahoo.com????
'
Xin chỉ giúp
 
Upvote 0
Nếu bạn dùng Office 2010 thì mọi chuyện quá đơn giản ---> Giống như bài này đây:
http://www.giaiphapexcel.com/forum/showthread.php?59491-Hỏi-về-code-VBA-chuyển-file-excel-sang-pdf
Trong quá trình record em có đặt tên file nhưng không thấy code và làm sao em có thể gửi mail được file Test001 này đi tới một địa chỉ ví dự yeulachet@yahoo.com????
Xin chỉ giúp
Trời... sao giống mail của mình thế nhỉ?
 
Upvote 0
Em không dùng 2010 anh NDU ạh
Em đã cài NovaPDF giờ chỉ còn mỗi việc đặt tên file và lưu vào đâu đó là em chưa làm được
Vì Macro ko record lại
 
Upvote 0
Em không dùng 2010 anh NDU ạh
Em đã cài NovaPDF giờ chỉ còn mỗi việc đặt tên file và lưu vào đâu đó là em chưa làm được
Vì Macro ko record lại
Cái kiểu code thế này e rằng khó cho người muốn giúp bạn, vì chẳng lẽ khi kiểm tra lại phải cài phần mềm gì đó sao?
 
Upvote 0
Tạm thời em tìm cách khắc phục được rồi ạh
Cám ơn anh
 
Upvote 0
Web KT

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

Back
Top Bottom