Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
How can I make this code work in whatever workbook is the current active
workbook? Right now, the only way it will work is to paste it into the workbook module. I want to put it in my personal.xls and run it from any workbook. Thanks. Sub Mail_every_Worksheet() Dim sh As Worksheet Dim wb As Workbook Dim strdate As String ShtCount = ActiveWorkbook.Sheets.Count <===== I thought this did it, but it doesn't do the trick Application.ScreenUpdating = False For Each sh In ThisWorkbook.Worksheets If sh.Range("a1").Value Like "*@*" Then strdate = Format(Now, "dd-mm-yy h-mm-ss") sh.Copy Set wb = ActiveWorkbook With wb .SaveAs "Sheet " & sh.name & " of " _ & ThisWorkbook.name & " " & strdate & ".xls" .SendMail ActiveSheet.Range("a1").Value, _ "This is the Subject line" .ChangeFileAccess xlReadOnly Kill .FullName .Close False End With End If Next sh Application.ScreenUpdating = True End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Annette
Change every ThisWorkbook in the code to ActiveWorkbook -- Regards Ron de Bruin http://www.rondebruin.nl "Annette" wrote in message ... How can I make this code work in whatever workbook is the current active workbook? Right now, the only way it will work is to paste it into the workbook module. I want to put it in my personal.xls and run it from any workbook. Thanks. Sub Mail_every_Worksheet() Dim sh As Worksheet Dim wb As Workbook Dim strdate As String ShtCount = ActiveWorkbook.Sheets.Count <===== I thought this did it, but it doesn't do the trick Application.ScreenUpdating = False For Each sh In ThisWorkbook.Worksheets If sh.Range("a1").Value Like "*@*" Then strdate = Format(Now, "dd-mm-yy h-mm-ss") sh.Copy Set wb = ActiveWorkbook With wb .SaveAs "Sheet " & sh.name & " of " _ & ThisWorkbook.name & " " & strdate & ".xls" .SendMail ActiveSheet.Range("a1").Value, _ "This is the Subject line" .ChangeFileAccess xlReadOnly Kill .FullName .Close False End With End If Next sh Application.ScreenUpdating = True End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks .. this is great ... and it finishes the project!
"Ron de Bruin" wrote in message ... Hi Annette Change every ThisWorkbook in the code to ActiveWorkbook -- Regards Ron de Bruin http://www.rondebruin.nl "Annette" wrote in message ... How can I make this code work in whatever workbook is the current active workbook? Right now, the only way it will work is to paste it into the workbook module. I want to put it in my personal.xls and run it from any workbook. Thanks. Sub Mail_every_Worksheet() Dim sh As Worksheet Dim wb As Workbook Dim strdate As String ShtCount = ActiveWorkbook.Sheets.Count <===== I thought this did it, but it doesn't do the trick Application.ScreenUpdating = False For Each sh In ThisWorkbook.Worksheets If sh.Range("a1").Value Like "*@*" Then strdate = Format(Now, "dd-mm-yy h-mm-ss") sh.Copy Set wb = ActiveWorkbook With wb .SaveAs "Sheet " & sh.name & " of " _ & ThisWorkbook.name & " " & strdate & ".xls" .SendMail ActiveSheet.Range("a1").Value, _ "This is the Subject line" .ChangeFileAccess xlReadOnly Kill .FullName .Close False End With End If Next sh Application.ScreenUpdating = True End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to make only the cells i need active | Excel Worksheet Functions | |||
copy worksheet from closed workbook to active workbook using vba | Excel Worksheet Functions | |||
Make a particular cell the active one | Excel Programming | |||
How do I make an open workbook the active workbook | Excel Programming | |||
Preventing opening workbook inside active workbook. | Excel Programming |