Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Make this the active workbook

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Make this the active workbook

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Make this the active workbook

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
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
How to make only the cells i need active debs1389 Excel Worksheet Functions 3 May 13th 06 07:49 PM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM
Make a particular cell the active one Newbie Excel Programming 3 April 14th 04 04:52 PM
How do I make an open workbook the active workbook Don Guillett[_4_] Excel Programming 0 December 30th 03 04:28 PM
Preventing opening workbook inside active workbook. Serge[_4_] Excel Programming 2 November 4th 03 07:51 PM


All times are GMT +1. The time now is 03:04 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"