홈>
아래 코드는 Excel 파일에서 데이터를 추출하여 이메일 주소로 모든 데이터를 통합하고 해당 이메일 주소로 데이터를 보냅니다. 잘 작동하지만 데이터를 더 좋아 보이게하려고합니다. 아래 정보에서 표를 만드는 방법이 있습니까?
이메일에 아래와 같은 헤더가 포함되도록하고 싶습니다 :
|_____|_____|_____|_____|
|_____|_____|_____|_____|
OFT 파일에 대한 임시 테이블을 보았지만 다음 코드를 사용하여 Excel에서 직접 볼 수는 없지만이 코드에서 동일한 작업을 수행하는 방법을 모르겠습니다.
tmpTbl = tmpTbl & "<tr><td></td><td></td><td align=""center"">*Company</td></tr></table>"
<시간>
Option Explicit
Sub Consolidate()
#If Early Then
Dim emailInformation As New Scripting.Dictionary
#Else
Dim emailInformation As Object
Set emailInformation = CreateObject("Scripting.Dictionary")
#End If
GetEmailInformation emailInformation
SendInfoEmail emailInformation
End Sub
Sub GetEmailInformation(emailInformation As Object)
Dim rg As Range
Dim sngRow As Range
Dim emailAddress As String
Dim myAppInfo As AppInfo
Dim AppInfos As Collection
Set rg = Range("A1").CurrentRegion ' Assuming the list starts in A1 and DOES NOT contain empty row
Set rg = rg.Offset(1).Resize(rg.Rows.Count - 1) ' Cut the headings
For Each sngRow In rg.Rows
emailAddress = sngRow.Cells(1, 1)
Set myAppInfo = New AppInfo
With myAppInfo
.app = sngRow.Cells(1, 2) 'code
.version = sngRow.Cells(1, 3) 'Company Name
.ticker = sngRow.Cells(1, 4) 'Abbreviation
.group = sngRow.Cells(1, 5) 'group sub group
.lead = sngRow.Cells(1, 6) 'leader
.banker = sngRow.Cells(1, 7) 'bank
.analyst = sngRow.Cells(1, 8) 'analyst
.otw = sngRow.Cells(1, 9) 'at
.rating = sngRow.Cells(1, 10) 'rank
.watchlist = sngRow.Cells(1, 11) 'Comments
.legal = sngRow.Cells(1, 12) 'notes
.add = sngRow.Cells(1, 13) 'Date
.last = sngRow.Cells(1, 14) 'Updated
.id = sngRow.Cells(1, 15) 'ID
End With
If emailInformation.Exists(emailAddress) Then
emailInformation.item(emailAddress).add myAppInfo
Else
Set AppInfos = New Collection
AppInfos.add myAppInfo
emailInformation.add emailAddress, AppInfos
End If
Next
End Sub
Sub SendInfoEmail(emailInformation As Object)
Dim sBody As String
Dim sBodyStart As String
Dim sBodyInfo As String
Dim sBodyEnd As String
Dim emailAdress As Variant
Dim colLines As Collection
Dim line As Variant
sBodyStart = "Hi, please find your info below:" & vbCrLf & vbCrLf
For Each emailAdress In emailInformation
Set colLines = emailInformation(emailAdress)
sBodyInfo = ""
For Each line In colLines
sBodyInfo = sBodyInfo & _
"Code: " & line.app & vbTab & "Company Name: " & line.app & vbTab & "abbreviation: " & line.abbreviation & vbTab & "Group Sub Group: " & line.group & vbTab & "Bank: " & line.lead & vbTab & "Analyst: " & line.analyst & vbTab & "at: " & line.at & vbTab & "Rank: " & line.rank & vbTab & "Comments: " & line.comments & vbTab & "Notes: " & line.notes & vbTab & "Date: " & line.add & vbTab & "Updated: " & line.updated & vbTab & "ID: " & line.id & vbCrLf
Next
sBodyEnd = "Best Regards," & vbCrLf & _
"Tom"
sBody = sBodyStart & sBodyInfo & sBodyEnd
SendEmail emailAdress, "Info", sBody
Next
End Sub
Sub SendEmail(ByVal sTo As String _
, ByVal sSubject As String _
, ByVal sBody As String _
, Optional ByRef coll As Collection)
#If Early Then
Dim ol As Outlook.Application
Dim outMail As Outlook.MailItem
Set ol = New Outlook.Application
#Else
Dim ol As Object
Dim outMail As Object
Set ol = CreateObject("Outlook.Application")
#End If
Set outMail = ol.CreateItem(0)
With outMail
.To = sTo
.Subject = sSubject
.Body = sBody
.VotingOptions = "Accept;Reject"
.Importance = 2
If Not (coll Is Nothing) Then
Dim item As Variant
For Each item In coll
.Attachments.add item
Next
End If
.Display
.Send
End With
Set outMail = Nothing
End Sub
- 답변 # 1
- 답변 # 2
이 코드를 테스트 할 확실한 방법이 없으므로 구문 오류가있을 수 있습니다. 필요한 경우 코드를 수정할 수 있도록 충분한 설명이 포함되어 있다고 생각합니다. 그렇지 않은 경우 오류가있는 설명을 게시하면 원인을 진단 할 것입니다.
가장 간단한 HTML을 사용했습니다. 더 많은 형식이 필요한 경우 몇 가지 제안을 해줄 수 있습니다.
Html 테이블은 다음과 같습니다.
<table> ... <table>
Html 행은 다음과 같습니다.
HTML 세포는 :<tr> ... </tr>
<td> ... </td>
Html 단락은 다음과 같습니다.
<p> ... </p>
이니 티즈
sBodyStart
그리고sBodyEnd
:sBodyStart = "<p>Hi, please find your info below:</p>" sBodyEnd = "<p>Best Regards,<br>Tom</p>"
신고에 추가 :
Dim CellValue As Variant
와이즈 비즈 교체
sbodyInfo = ""
로 포함 :Next
sBodyInfo = "<table>" sBodyInfo = sBodyInfo & "<tr>" For Each CellValue in Array("Code", "Company Name", "Abbreviation", _ "Group Sub Group", "Bank", "Analyst", _ "At","Rank","Comments","Notes","Date", _ "Updated","ID") sBodyInfo = sBodyInfo & "<td>" & CellValue & "</td>" Next sBodyInfo = sBodyInfo & "</tr>" For Each line In colLines sBodyInfo = sBodyInfo & "<tr>" For Each CellValue in Array(line.app, line.app, line.abbreviation, _ line.group, line.lead, line.analyst, _ line.at, line.rank, line.comments, _ line.notes, line.add, line.updated, line.id) sBodyInfo = sBodyInfo & "<td>" & CellValue & "</td>" Next sBodyInfo = sBodyInfo & "</tr>" Next sBodyInfo = sBodyInfo & "</table>"
관련 자료
- linux - 목록에서 특정 텍스트를 대문자로 표시하는 방법은 무엇입니까?
- java - 텍스트 파일에서 한 줄의 각 문자를 행렬로 읽고 2D 행렬을 만드는 방법은 무엇입니까?
- python - 파일에서 텍스트를 읽고 내림차순으로 정렬하는 방법은 무엇입니까?
- sql - 조인으로 테이블에서 삭제하는 방법
- javascript - json 테이블에서 삭제하는 방법은 무엇입니까?
- python - 텍스트 파일에서 사전을 어떻게로드합니까?
- c# - 데이터가 구성되지 않은 텍스트 파일에서 읽는 방법은 무엇입니까?
- java - 테이블에서 행을 선택하는 방법?
- python - 변수에서 경로를 만드는 방법은 무엇입니까?
- 자바 스크립트 애플리케이션에서 HTML 텍스트 영역 상자로 텍스트를 보내는 방법은 무엇입니까?
- python - URL에서 원시 텍스트를 인쇄하는 방법은 무엇입니까?
- D3js의 csv 파일에서 매핑 할 데이터를 그리는 방법
- 파이썬 스크래피에서 텍스트 만 얻을 수있는 방법
- ios - 내부에서 던지는 방법
- javascript - 끝점의 데이터를 플롯으로 표시하는 방법은 무엇입니까?
- sql - 파이썬을 사용하여 psql 데이터베이스에 테이블을 만드는 방법은 무엇입니까?
- python - 파이 게임에서 아랍어/페르시아어 텍스트와 글꼴을 수정하는 방법은 무엇입니까?
- powerbi - 데이터 흐름 매핑에서 동적 날짜 테이블을 만들 수 있습니까?
- sql - 듀얼에서 날짜 테이블 만들기
- drupal - json에서 콘텐츠를 마이그레이션하는 방법은 무엇입니까?
관련 질문
- Excel VBA에서 열에서 키워드 찾기 및 다른 열 편집
- excel : 마지막 행 IF를 찾는 매크로 도움말
- excel : 셀 색상을 확인/변경하기 위해 Change(byVal Target as Range)를 어떻게 사용합니까?
- excel : PC 스토리지 드라이브 이름 찾기
- excel : 성공적인 브라우저 시작 요청에 대한 동일한 페이로드에도 불구하고 VBA가 있는 HTTPRequest를 통한 "잘못된 다중 부분 페이로드 형식"
- excel : 수식 숫자 값을 숫자 더하기 1로 바꾸기
- excel : 값이 날짜를 따르도록 vlookup 또는 매크로를 설정하는 방법
- excel : 다른 이름으로 저장하는 동안 파일을 바꾸라는 메시지가 표시되면 "아니요" 또는 "취소"를 선택하면 VBA 1004 오류가 발생합니다.
- Excel 스프레드시트에 값을 쓰도록 확인란을 얻으려고 합니다.
- excel : 여러 If/Then 호출 옵션
일반 텍스트
Body
를 설정하는 대신 속성, 테이블과 함께 유효한 HTML 문자열을 구성하고HTMLBody
에 할당