Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

E-mail spreadsheet

Status
Not open for further replies.

tenbellies

Programmer
Dec 20, 2002
17
GB
aaarghhhh can any one help, I have to write a macro in excel that when the spreadsheet opens it automatically runs a macro rereshs itself and e-mails itself out.

The refresh i have sorted but can i get it to run the macro on open and then e-mail out to a distribution list?

 


Hi,

Take a look at the Workbook_Open event.

Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
tenbellies,
there have been numerous posts here regarding this, i believe. but to get you started:
Code:
Sub Auto_Open()
    Application.Run "dsnocoitm.xls!Menus"
End Sub
will run the macro to put it on the tool bar whenever the spreadsheet is open
Code:
Sub Menus()
With MenuBars("Worksheet")
    .Reset
    .Menus.Add ("&Macros")
    With .Menus("&Macros")
      .MenuItems.Add ("Macro1&1"), "Macro1"
    End With
  End With
  newHour = Hour(Now())
  newMinute = Minute(Now())
  newSecond = Second(Now()) + 1
  waitTime = TimeSerial(newHour, newMinute, newSecond)
  Application.Run "dsnocoitm.xls!Macro1"
End Sub
puts the macro on the toolbar waits 1 sec then actually runs the macro
Code:
Sub macro1()
Dim newHour As Variant
Dim newMinute As Variant
Dim newSecond As Variant
Dim waitTime As Variant

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
If IsNull(Application.MailSession) Then
 Application.MailLogon "MS Exchange Settings", , False
End If
   ChDir "C:\aafiles"
'code for refreshing your xls here
ActiveWorkbook.SendMail Recipients:=Array("user1@company.com", "user2@company.com")
Workbooks("wbname_" & Format(Now(), "yyyymmdd") & ".xls").Close SaveChanges:=False
Application.DisplayAlerts = True

Application.Quit
End Sub
how to get the data is left as an exercise for the user.
regards,
longhair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top