Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default send e-mail from Excel, copy and paste at specific place in e-mail

Dear experts,


I am writing VBA in Excel to try to automate the daily reporting of sending
data from Excel through e-mail. I got stuck at getting Excel to paste the
clipboard data into the right place in e-mail. The codes:
Sub SendDailyReport()
Dim objOutlook As Outlook.Application
Dim Doc As Word.Document
Dim wdRange As Word.Range
Dim objEmail As Outlook.MailItem
Dim wbBook As Workbook
Dim wsSheet As Worksheet

Application.ScreenUpdating = False
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = New Outlook.Application
objInbox.Display
End If

Set wbBook = ThisWorkbook
Set wsSheet = ThisWorkbook.Worksheets("reporting")
wsSheet.Activate
With ActiveSheet.UsedRange
..Copy
End With

Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
..Importance = olImportanceHigh
..Subject = "Daily Report " & FormatDateTime(Date, vbLongDate)
..To = "Senior Managers"
..Body = "Dear Sir, " & vbCrLf & vbCrLf & _
"Daily Report As Show Below:" & vbCrLf & vbCrLf & vbCrLf & _
vbCrLf & vbCrLf & "Thanks and Best Regards," & vbCrLf & vbCrLf & _
"Security Group" & vbCrLf & "Extension Number: 27555"
..Display
Set Doc = objEmail.GetInspector.WordEditor
Set wdRange = Doc.Range
wdRange.Paste
End With
Set wsSheet = ThisWorkbook.Worksheets("chart")
wsSheet.Range("A19:AD59").Copy
objEmail.Display
wdRange.Paste
Application.CutCopyMode = False 'clear the clipboard
ExitSub:
Set objNewMail = Nothing
Set objInbox = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing
Exit Sub

As of now, the paste into e-mail will overwrite whatever is already there. I
want the first paste (from worksheet "reporting") to paste right after the
"Daily Report As Show Below:" line and the 2nd paste (from worksheet
"Chart") to paste right below the first pasted data.

How do I manipulate the range or cursor so that I can paste at the right
place? Any help is very much appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default send e-mail from Excel, copy and paste at specific place in e-mail

Try
http://www.rondebruin.nl/mail/folder3/mail4.htm

Read also the Tip below the macro



"Hii Sing Chung" wrote:

Dear experts,


I am writing VBA in Excel to try to automate the daily reporting of sending
data from Excel through e-mail. I got stuck at getting Excel to paste the
clipboard data into the right place in e-mail. The codes:
Sub SendDailyReport()
Dim objOutlook As Outlook.Application
Dim Doc As Word.Document
Dim wdRange As Word.Range
Dim objEmail As Outlook.MailItem
Dim wbBook As Workbook
Dim wsSheet As Worksheet

Application.ScreenUpdating = False
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = New Outlook.Application
objInbox.Display
End If

Set wbBook = ThisWorkbook
Set wsSheet = ThisWorkbook.Worksheets("reporting")
wsSheet.Activate
With ActiveSheet.UsedRange
.Copy
End With

Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.Importance = olImportanceHigh
.Subject = "Daily Report " & FormatDateTime(Date, vbLongDate)
.To = "Senior Managers"
.Body = "Dear Sir, " & vbCrLf & vbCrLf & _
"Daily Report As Show Below:" & vbCrLf & vbCrLf & vbCrLf & _
vbCrLf & vbCrLf & "Thanks and Best Regards," & vbCrLf & vbCrLf & _
"Security Group" & vbCrLf & "Extension Number: 27555"
.Display
Set Doc = objEmail.GetInspector.WordEditor
Set wdRange = Doc.Range
wdRange.Paste
End With
Set wsSheet = ThisWorkbook.Worksheets("chart")
wsSheet.Range("A19:AD59").Copy
objEmail.Display
wdRange.Paste
Application.CutCopyMode = False 'clear the clipboard
ExitSub:
Set objNewMail = Nothing
Set objInbox = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing
Exit Sub

As of now, the paste into e-mail will overwrite whatever is already there. I
want the first paste (from worksheet "reporting") to paste right after the
"Daily Report As Show Below:" line and the 2nd paste (from worksheet
"Chart") to paste right below the first pasted data.

How do I manipulate the range or cursor so that I can paste at the right
place? Any help is very much appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default send e-mail from Excel, copy and paste at specific place in e-mail

Dear Ron,
Thank you for your message. I've read the codes and the tip but still it
doesn't do exactly want I wanted. I want to be able to insert the data from
the clipboard (which is copied from Excel) into the correct place, a
position in between the salutation and the signature in Outlook e-mail, and
then follow by another copy-and-paste from Excel into the e-mail at the
position right after the first paste. I must use Word for e-mail editing,
that is for consistency.

"Ron de Bruin" wrote in message
...
Try
http://www.rondebruin.nl/mail/folder3/mail4.htm

Read also the Tip below the macro



"Hii Sing Chung" wrote:

Dear experts,


I am writing VBA in Excel to try to automate the daily reporting of
sending
data from Excel through e-mail. I got stuck at getting Excel to paste the
clipboard data into the right place in e-mail. The codes:
Sub SendDailyReport()
Dim objOutlook As Outlook.Application
Dim Doc As Word.Document
Dim wdRange As Word.Range
Dim objEmail As Outlook.MailItem
Dim wbBook As Workbook
Dim wsSheet As Worksheet

Application.ScreenUpdating = False
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = New Outlook.Application
objInbox.Display
End If

Set wbBook = ThisWorkbook
Set wsSheet = ThisWorkbook.Worksheets("reporting")
wsSheet.Activate
With ActiveSheet.UsedRange
.Copy
End With

Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.Importance = olImportanceHigh
.Subject = "Daily Report " & FormatDateTime(Date, vbLongDate)
.To = "Senior Managers"
.Body = "Dear Sir, " & vbCrLf & vbCrLf & _
"Daily Report As Show Below:" & vbCrLf & vbCrLf & vbCrLf & _
vbCrLf & vbCrLf & "Thanks and Best Regards," & vbCrLf & vbCrLf &
_
"Security Group" & vbCrLf & "Extension Number: 27555"
.Display
Set Doc = objEmail.GetInspector.WordEditor
Set wdRange = Doc.Range
wdRange.Paste
End With
Set wsSheet = ThisWorkbook.Worksheets("chart")
wsSheet.Range("A19:AD59").Copy
objEmail.Display
wdRange.Paste
Application.CutCopyMode = False 'clear the clipboard
ExitSub:
Set objNewMail = Nothing
Set objInbox = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing
Exit Sub

As of now, the paste into e-mail will overwrite whatever is already
there. I
want the first paste (from worksheet "reporting") to paste right after
the
"Daily Report As Show Below:" line and the 2nd paste (from worksheet
"Chart") to paste right below the first pasted data.

How do I manipulate the range or cursor so that I can paste at the right
place? Any help is very much appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default send e-mail from Excel, copy and paste at specific place in e-mail

must use Word for e-mail editing

I think the best way is to create a new sheet with code and copy all the stuff you
want with code on that sheet and mail it and delete it after that

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Hii Sing Chung" wrote in message ...
Dear Ron,
Thank you for your message. I've read the codes and the tip but still it
doesn't do exactly want I wanted. I want to be able to insert the data from
the clipboard (which is copied from Excel) into the correct place, a
position in between the salutation and the signature in Outlook e-mail, and
then follow by another copy-and-paste from Excel into the e-mail at the
position right after the first paste. I must use Word for e-mail editing,
that is for consistency.

"Ron de Bruin" wrote in message
...
Try
http://www.rondebruin.nl/mail/folder3/mail4.htm

Read also the Tip below the macro



"Hii Sing Chung" wrote:

Dear experts,


I am writing VBA in Excel to try to automate the daily reporting of
sending
data from Excel through e-mail. I got stuck at getting Excel to paste the
clipboard data into the right place in e-mail. The codes:
Sub SendDailyReport()
Dim objOutlook As Outlook.Application
Dim Doc As Word.Document
Dim wdRange As Word.Range
Dim objEmail As Outlook.MailItem
Dim wbBook As Workbook
Dim wsSheet As Worksheet

Application.ScreenUpdating = False
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = New Outlook.Application
objInbox.Display
End If

Set wbBook = ThisWorkbook
Set wsSheet = ThisWorkbook.Worksheets("reporting")
wsSheet.Activate
With ActiveSheet.UsedRange
.Copy
End With

Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.Importance = olImportanceHigh
.Subject = "Daily Report " & FormatDateTime(Date, vbLongDate)
.To = "Senior Managers"
.Body = "Dear Sir, " & vbCrLf & vbCrLf & _
"Daily Report As Show Below:" & vbCrLf & vbCrLf & vbCrLf & _
vbCrLf & vbCrLf & "Thanks and Best Regards," & vbCrLf & vbCrLf &
_
"Security Group" & vbCrLf & "Extension Number: 27555"
.Display
Set Doc = objEmail.GetInspector.WordEditor
Set wdRange = Doc.Range
wdRange.Paste
End With
Set wsSheet = ThisWorkbook.Worksheets("chart")
wsSheet.Range("A19:AD59").Copy
objEmail.Display
wdRange.Paste
Application.CutCopyMode = False 'clear the clipboard
ExitSub:
Set objNewMail = Nothing
Set objInbox = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing
Exit Sub

As of now, the paste into e-mail will overwrite whatever is already
there. I
want the first paste (from worksheet "reporting") to paste right after
the
"Daily Report As Show Below:" line and the 2nd paste (from worksheet
"Chart") to paste right below the first pasted data.

How do I manipulate the range or cursor so that I can paste at the right
place? Any help is very much appreciated.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default send e-mail from Excel, copy and paste at specific place in e-mail

Thanks Ron,

As the format of the e-mail is defined by the recipients (the Senior
Management), it has to be done that way, cannot be just send the spreadsheet
to the recipients.
Right now what I do is to put all the text into the Excel worksheet itself
and the chart portion also put a copy into this worksheet and when pasting
into e-mail, it pastes once and everything. That serves the purpose but I am
still researching on how to paste into the correct position or any position
I want.

"Ron de Bruin" wrote in message
...
must use Word for e-mail editing


I think the best way is to create a new sheet with code and copy all the
stuff you
want with code on that sheet and mail it and delete it after that

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Hii Sing Chung" wrote in message
...
Dear Ron,
Thank you for your message. I've read the codes and the tip but still it
doesn't do exactly want I wanted. I want to be able to insert the data
from the clipboard (which is copied from Excel) into the correct place, a
position in between the salutation and the signature in Outlook e-mail,
and then follow by another copy-and-paste from Excel into the e-mail at
the position right after the first paste. I must use Word for e-mail
editing, that is for consistency.

"Ron de Bruin" wrote in message
...
Try
http://www.rondebruin.nl/mail/folder3/mail4.htm

Read also the Tip below the macro



"Hii Sing Chung" wrote:

Dear experts,


I am writing VBA in Excel to try to automate the daily reporting of
sending
data from Excel through e-mail. I got stuck at getting Excel to paste
the
clipboard data into the right place in e-mail. The codes:
Sub SendDailyReport()
Dim objOutlook As Outlook.Application
Dim Doc As Word.Document
Dim wdRange As Word.Range
Dim objEmail As Outlook.MailItem
Dim wbBook As Workbook
Dim wsSheet As Worksheet

Application.ScreenUpdating = False
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = New Outlook.Application
objInbox.Display
End If

Set wbBook = ThisWorkbook
Set wsSheet = ThisWorkbook.Worksheets("reporting")
wsSheet.Activate
With ActiveSheet.UsedRange
.Copy
End With

Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.Importance = olImportanceHigh
.Subject = "Daily Report " & FormatDateTime(Date, vbLongDate)
.To = "Senior Managers"
.Body = "Dear Sir, " & vbCrLf & vbCrLf & _
"Daily Report As Show Below:" & vbCrLf & vbCrLf & vbCrLf & _
vbCrLf & vbCrLf & "Thanks and Best Regards," & vbCrLf & vbCrLf
& _
"Security Group" & vbCrLf & "Extension Number: 27555"
.Display
Set Doc = objEmail.GetInspector.WordEditor
Set wdRange = Doc.Range
wdRange.Paste
End With
Set wsSheet = ThisWorkbook.Worksheets("chart")
wsSheet.Range("A19:AD59").Copy
objEmail.Display
wdRange.Paste
Application.CutCopyMode = False 'clear the clipboard
ExitSub:
Set objNewMail = Nothing
Set objInbox = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing
Exit Sub

As of now, the paste into e-mail will overwrite whatever is already
there. I
want the first paste (from worksheet "reporting") to paste right after
the
"Daily Report As Show Below:" line and the 2nd paste (from worksheet
"Chart") to paste right below the first pasted data.

How do I manipulate the range or cursor so that I can paste at the
right
place? Any help is very much appreciated.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Send mail from excel - Copy/paste unformatted values and error Brice Excel Programming 5 February 12th 09 12:22 AM
Send mail from excel - Copy/paste unformatted values and error mes Brice Excel Programming 6 February 6th 09 03:40 AM
Programming Excel to send an e-mail when specific conditions are m SiDai Excel Programming 1 January 23rd 09 05:07 PM
How to send specific cell ranges to multiple e-mail addresses Meghan Excel Programming 0 October 16th 06 06:14 PM
Excel Copy and Paste into Outlook e-mail Compuser Excel Programming 2 December 5th 04 10:11 AM


All times are GMT +1. The time now is 03:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"