Hi
I have a macro that emails individual tabs to the address states in each tabs' A1 cell
The issue I have is that I want to use this macro from my personal workbook. But when I try, the macro looks for the email address in A1 of my personal macro book, rather than the workbook I want to send out. The code doesnt say 'look at my personal macro book', but as it is constantly creating new temp files im not sure where to start. How can I stop the macro looking at my personal book?Sub Email_All() Dim sh As Worksheet Dim wb As Workbook Dim FileExtStr As String Dim FileFormatNum As Long Dim TempFilePath As String Dim TempFileName As String Dim OutApp As Object Dim OutMail As Object TempFilePath = Environ$("temp") & "\" If Val(Application.Version) < 12 Then FileExtStr = ".xls": FileFormatNum = -4143 Else FileExtStr = ".xlsm": FileFormatNum = 52 End If With Application .ScreenUpdating = True .EnableEvents = False End With Set OutApp = CreateObject("Outlook.Application") For Each sh In ThisWorkbook.Worksheets If sh.Range("A1").Value Like "?*@?*.?*" Then sh.Copy Set wb = ActiveWorkbook TempFileName = "Sheet " & sh.Name & " of " _ & ThisWorkbook.Name & " " _ & Format(Now, "dd-mmm-yy h-mm-ss") Set OutMail = OutApp.CreateItem(0) With wb .SaveAs TempFilePath & TempFileName & FileExtStr, _ FileFormat:=FileFormatNum On Error Resume Next With OutMail .To = sh.Range("A1").Value .CC = "" .BCC = "" .Subject = UF_Email.Txt_Subject.Text .htmlBody = UF_Email.Txt_Intro & "<br><br>" & UF_Email.TxtText & "<br><br>" & UF_Email.Txt_Name.Text & "<br><br>" & UF_Email.Txt_Title & "<br><br>" & UF_Email.Txt_Tel .Attachments.Add wb.FullName End With On Error GoTo 0 .Close SaveChanges:=False End With Set OutMail = Nothing Kill TempFilePath & TempFileName & FileExtStr End If Next sh Set OutApp = Nothing With Application .ScreenUpdating = True .EnableEvents = True End With UF_Email.Hide End Sub
Thank You
Last edited by cooket4; 02-03-2012 at 09:51 AM.
Thisworkbook refers to the workbook that contains the code, you need activeworkbook instead
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
wow sounds so simple! so if i change every 'thisworkbook' to 'activeworkbook' it should work?
works like a charm!! thank you
No problem
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks