![]() |
|
||
| This thread is about: technical excel macro help please!, it's in Any non Civic chat here please! at the Honda Civic forum Civinfo; got a fabby macro running in my excel spreadsheet, but now I've hit a problem And I'm hoping some wiz out there might be able ... | ||
| Help Search Stickers Surveys Wiki Forum |
|
|
|||||||
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Super Moderator
Civinfo master
Join Date: 4th August 2006
Location: Cardiff
Posts: 5,638
Thanks: 0
Thanked 1 Time in 1 Post
|
technical excel macro help please!
got a fabby macro running in my excel spreadsheet, but now I've hit a problem And I'm hoping some wiz out there might be able to help! I've got a sheet with all my data on, sorted by outlet. Each seperate outlet needs to get the data for just their own store. I can get the macro to dynamically extract each store's info into a new sheet without a problem - BUT I now need to send this data in an email. If (under macro control) I create an email with an attachment, I loose control from the macro (cos the PC is now running Outlook) and even the email address (copied by macro from the appropriate cell) refuses to paste into the To box (even manually) If I create the email as a 'for review' I can (manually) paste the email address in, but again, not by the macro as it's not 'in control' of the email does anyone have any ideas please? I need to make this a 'push the button and forget' operation, as it's got to work for muppet users - sorry, I mean it needs to be foolproof any suggestions gratefully received! But I'm constrained to using excel and Outlook, as it's a work app |
|
|
|
|
|
#2 (permalink) |
|
Supporter
Triangular Exhaust
Join Date: 15th June 2006
Location: London
Posts: 308
Thanks: 1
Thanked 0 Times in 0 Posts
|
are you using the CreateItem(olMailItem) method to create your email?
mind you if i were you i'd get into access and run queries and stuff form there, I have a database that puts data out to email and is one button muppet proof job |
|
|
|
|
|
#3 (permalink) |
|
Administrator
Civinfo guru
Join Date: 10th April 2006
Location: Leics
Posts: 4,985
Thanks: 8
Thanked 91 Times in 49 Posts
|
I have had to do this before and I remember it all getting a bit unstuck. Ended up coding it in VB6 instead...
But here's a bit pinched from a quick Google... Code:
Sub SendEmail()
ESubject = "This is a test email"
SendTo = "Some_Address@ADomain.com"
CCTo = "Different_Address@ADomain.com"
Ebody = "Testing VBA's ability to send an email."
NewFileName = "C:\My Documents\TestFile.xls"
Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = ESubject
.To = SendTo
.CC = CCTo
.Body = Ebody
'.Attachments.Add (NewFileName) ' Must be complete path
'.Display ' This property is used when you want
' the user to see email and manually send. Then
' comment out rest of code except “End With” statement
' and "End Sub" statement.
.send
End With
Set App = Nothing
Set Itm = Nothing
End Sub
|
|
|
|
|
|
#4 (permalink) |
|
Locking Wheelnut
Join Date: 5th June 2006
Location: Buxton, UK
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
|
I've created an App using very similar logic to this, except I stopped at the .display, so the user could add text if necessary, then click on Send.
Can't remember why now, but I also had, at the beginning: On Error Resume Next Set OutlookApp = GetObject(, "Outlook.Application") If Err <> 0 Then 'Outlook not running - start it Me.MousePointer = vbHourglass Err.Clear Set OutlookApp = CreateObject("Outlook.Application") DoEvents If Err <> 0 Then MsgBox "Please start Outlook then try again" Err.Clear End If Me.MousePointer = vbDefault End If On Error GoTo 0 I think the CreateObject failed if the user already had Outlook open. |
|
|
|
|
|
#8 (permalink) |
|
Super Moderator
Civinfo master
Join Date: 4th August 2006
Location: Cardiff
Posts: 5,638
Thanks: 0
Thanked 1 Time in 1 Post
|
many thanks for all the replies!
I've actually taken inspiration from each of them, scratched my head a lot, perused the (fairly useless!) help topics, and come up with... macros copies relevant data into new worksheet B1 contains the report title = "Report for 2006/10/18" B3 contains (dynamically) the email address of the recipients C3 contains (dynamically) the store name Code:
emailstore = range("b3").value
emailsubj = range("b1").value + " - " + range("c3").value
activeworkbook.sendmail Recipients:=emailstore, subject:=emailsubj
MANY thanks again for all the replies - much appreciated! |
|
|
|
|
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Technical Specifications | davidj241 | Wiki Article Discussion | 2 | 17th July 2008 11:08 |
| Faults Technical Hints and Tips | m4rky | Engines and Transmission | 12 | 21st October 2007 11:45 |
| HondaJet Flight Demonstration and Technical Briefing to be Held at EAA AirVenture Osh | Honda News Feed | Honda News | 0 | 2nd November 2006 22:44 |