Lưu file excel thành pdf ra desktop (4 người xem)

Liên hệ QC

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

alex-luu

Thành viên thường trực
Tham gia
10/3/15
Bài viết
300
Được thích
52
Em có file excel với Macro lưu file thành pdf ra Desktop như sau :

Sub Export()
ChDir "D:\Backup\G-Driver\Desktop"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\Backup\G-Driver\Desktop\Book1.pdf", Quality:=xlQualityStandard _
, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True

End Sub

Khi chép file này qua máy khác thì Macro không hoạt động được vì sai đường dẫn. Có cách nào sửa để nó hoạt động trên nhiều máy khác nhau không, xin mọi người chỉ giúp
Em cảm ơn
 
Em có file excel với Macro lưu file thành pdf ra Desktop như sau :

Sub Export()
ChDir "D:\Backup\G-Driver\Desktop"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\Backup\G-Driver\Desktop\Book1.pdf", Quality:=xlQualityStandard _
, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True

End Sub

Khi chép file này qua máy khác thì Macro không hoạt động được vì sai đường dẫn. Có cách nào sửa để nó hoạt động trên nhiều máy khác nhau không, xin mọi người chỉ giúp
Em cảm ơn
Thư mục Desktop là cái này:
Mã:
CreateObject("WScript.Shell").SpecialFolders("Desktop")
 
Thư mục Desktop là cái này:
Mã:
CreateObject("WScript.Shell").SpecialFolders("Desktop")
Dạ, em cảm ơn thầy NDU, em làm được rồi

Sub Export()
Dim strDesktop As String
strDesktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
ThisWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=strDesktop & "\book1 .pdf"
End Sub
 
Vậy nếu như em chỉ nuốn xuất Sheet1 ra thành File pdf thôi thì chỉnh code làm sao hả Thầy ndu???
 
Dạ, em cảm ơn thầy NDU, em làm được rồi

Sub Export()
Dim strDesktop As String
strDesktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
ThisWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=strDesktop & "\book1 .pdf"
End Sub
em chỉ muối xuất theo từng sheet thì code chỉnh sao Thầy Du ơi
 
chỗ \book1 .pdf bạn sửa thành "\"&activesheet.name&".pdf"
k dc bạn

Sub Export()
Dim strDesktop As String
strDesktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _

Filename:=strDesktop & "\"&activesheet.name&".pdf"

End Sub
 
cảm ơn bạn!
 
Nếu em chỉ chọn một vùng nào đó để lưu thành file pdf (như A:H50 của sheet1) thì chỉnh code sao ah????
 
Cám ơn mọi người. Em đã làm được.
Mã:
Sub Export()
Dim strDesktop As String
strDesktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
ActiveSheet.Range("A1:H50").ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=strDesktop & "\" & ActiveSheet.Name & " .pdf"
End Sub
 
CUntitled.pngách này nếu ai cài office 2010 thi không cần code vẫn vèo vèo
 
Nhớ là từ Office 2010 trở đi, có lệnh Published to PDF or XPS của Excel rồi, code kiếc chi cho mệt vậy!
 
Nhớ là từ Office 2010 trở đi, có lệnh Published to PDF or XPS của Excel rồi, code kiếc chi cho mệt vậy!
Người ta hỏi là có lý do chứ bạn. Ví dụ người ta đang làm 1 dự án lớn, trong đó có công đoạn Save to PDF. Vậy viết code đến khúc này thì ngưng và mình sẽ save file bằng tay à?
 
Web KT

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

Back
Top Bottom