Dán dữ liệu dạng Keep Text Ony từ Excel vào Outlook bằng VBA (1 người xem)

Liên hệ QC

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

MinhKhai

Giải pháp Ếc-xào
Tham gia
16/4/08
Bài viết
941
Được thích
572
Chào các anh chị
Hàng ngày em phải gửi email theo định dạng như hình dưới. Em có tạo file và nhập liệu từ Excel rồi dùng VBA để mở sẵn New Message trong Outlook, sau đó Paste thủ công dạng Keep Text Only vào Outlook.
Nhờ các anh chị giúp đỡ code VBA để sao cho khi bấm nút trong Excel, New Message của Outlook mở ra và vùng dữ liệu trong Excel được copy và dán dạng Keep Text Only luôn vào.
Xin cảm ơn các anh chị !

1700761448749.png
 

File đính kèm

Vấn đề này chẳng lẽ VBA Excel không đẩy dữ liệu copy được sang MS Outlook ?
 
Upvote 0
PHP:
Private Sub CmdOpenOutlook_Click()

    Application.ScreenUpdating = False

    'Sort theo UT
    Worksheets("LGH").Sort.SortFields.Clear
    Range("D10:I17").Sort Key1:=Range("H10"), Order1:=xlAscending, Header:=xlNo
    Sheet11.Range("D10:D18").SpecialCells(4).EntireRow.Hidden = True
    CmdFCShow.Caption = "Show All Rows"

    'Dulieu
    Dim TempRange As Range
    Set TempRange = Sheet11.Range("D9:I19").SpecialCells(xlCellTypeVisible)
    'Copy TempRange vào clipboard
    TempRange.Copy

    'Mo Outlook
    Dim ObjMail As Object
    Set ObjMail = CreateObject("Outlook.Application").CreateItem(0)

    'Paste Keep Text Only
    With ObjMail.GetInspector.WordEditor.Range
        .PasteSpecial DataType:=wdPasteText
    End With

    With ObjMail
        .To = "test@gmail.com"
        .Subject = Sheet11.[F4]
        .Importance = 2
        .Display
    End With

    Set TempRange = Nothing
    Set ObjMail = Nothing

    Application.ScreenUpdating = True

End Sub
Bạn xem thử. Trong Reference bạn chọn
1701053183011.png
 
Upvote 0
PHP:
Private Sub CmdOpenOutlook_Click()

    Application.ScreenUpdating = False

    'Sort theo UT
    Worksheets("LGH").Sort.SortFields.Clear
    Range("D10:I17").Sort Key1:=Range("H10"), Order1:=xlAscending, Header:=xlNo
    Sheet11.Range("D10:D18").SpecialCells(4).EntireRow.Hidden = True
    CmdFCShow.Caption = "Show All Rows"

    'Dulieu
    Dim TempRange As Range
    Set TempRange = Sheet11.Range("D9:I19").SpecialCells(xlCellTypeVisible)
    'Copy TempRange vào clipboard
    TempRange.Copy

    'Mo Outlook
    Dim ObjMail As Object
    Set ObjMail = CreateObject("Outlook.Application").CreateItem(0)

    'Paste Keep Text Only
    With ObjMail.GetInspector.WordEditor.Range
        .PasteSpecial DataType:=wdPasteText
    End With

    With ObjMail
        .To = "test@gmail.com"
        .Subject = Sheet11.[F4]
        .Importance = 2
        .Display
    End With

    Set TempRange = Nothing
    Set ObjMail = Nothing

    Application.ScreenUpdating = True

End Sub
Bạn xem thử. Trong Reference bạn chọn
View attachment 297081
Bác ơi, em test nó chạy như mong muốn rồi. Có 1 vấn đề này mong bác xử lý nốt giúp, đó là làm sao để nối cái Signature mặc định trong Outlook vào nội dung này. Cảm ơn bác
 
Upvote 0
Web KT

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

Back
Top Bottom