Tài liệu vba for excel bằng tiếng việt

-

Trong nội dung bài viết này

Summary

This article describes a Visual Basic for Applications macro that uses data from a loadingvn.com Word document & a loadingvn.com Excel workbook to lớn send messages from loadingvn.com Outlook.

Bạn đang xem: Tài liệu vba for excel bằng tiếng việt

More information


Important

loadingvn.com provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated và with the tools that are used to lớn create & to debug procedures. loadingvn.com tư vấn engineers can help explain the functionality of a particular procedure, but they will not modify these examples lớn provide added functionality or construct procedures to lớn meet your specific requirements.

Xem thêm: Cô Đỗ Tú Oanh Dạy Văn Ở Đâu, 6 Giáo Viên Luyện Thi Môn Văn Nổi Tiếng Hà Nội


The following example assumes that there are two defined names in the worksheet:

The first defined name, subjectcell, refers to a cell that contains the message subject line (for example, "This is a kiểm tra message.").The second defined name, tolist, refers to lớn the first cell in the horizontal danh mục that contains a danh mục of recipients (for example, "John Doe", "Jane Doe", và so forth).

You must also have a loadingvn.com Word document. The text of this document is used by the macro as the message body of your mail message.

Sub SendOutlookMessages()"Dimension variables. Dim OL As Object, MailSendItem As Object Dim W As Object Dim MsgTxt As String, SendFile As String Dim ToRangeCounter As Variant "Identifies Word file to send SendFile = Application.GetOpenFilename(Title:="Select MS Word " & _ "file to mail, then click "Open"", buttontext:="Send", _ MultiSelect:=False)"Starts Word session mix W = GetObject(SendFile)"Pulls text from tệp tin for message body toàn thân MsgTxt = W.Range(Start:=W.Paragraphs(1).Range.Start, _ End:=W.Paragraphs(W.Paragraphs.Count).Range.End)"Ends Word session set W = Nothing "Starts Outlook session mix OL = CreateObject("Outlook.Application") set MailSendItem = OL.CreateItem(olMailItem) ToRangeCounter = 0 "Identifies number of recipients for to list. For Each xCell In ActiveSheet.Range(Range("tolist"), _ Range("tolist").End(xlToRight)) ToRangeCounter = ToRangeCounter + 1 Next xCell If ToRangeCounter = 256 Then ToRangeCounter = 1 "Creates message With MailSendItem .Subject = ActiveSheet.Range("subjectcell").Text .Body = MsgTxt "Creates "To" danh mục For Each xRecipient In Range("tolist").Resize(1, ToRangeCounter) RecipientList = RecipientList và ";" và xRecipient Next xRecipient .To = RecipientList .Send end With "Ends Outlook session mix OL = Nothing kết thúc Sub