weiser386
New Member
- Joined
- Sep 2, 2015
- Messages
- 10
DON'T MIND MY SLOPPY CODE I'M JUST WINGING IT! ha
OK so here is my problem...I have a worksheet that displays production data on a TV monitor in the production office. This worksheet is generated by iHistorian tags and i have it set to update every 3 seconds (so we can see when equipment goes down, and the speed of the equipment "real time") I just created a macro that takes a screen shot of the report at the end of every shift (12 hour shift so they end at 7am and 7pm) then it saves the screen shot in a folder so it can be emailed out to everyone at the end of every shift (i still need help automating this screen shot to be embedded in the body of the email but that's another story) so to get to the point i added a application.ontime for this said screen shot and i dont know how to stop it after it takes the screen shot, so it takes a screen shot every 3 seconds....I need help!! thank you in advance!!!
(OH AND HOW DO YOU PUT CODE IN YOUR POST SO IT LOOKS LIKE REGULAR CODE INSTEAD OF PLAIN TEXT???)
Sorry i know this is a lot but you guys are awesome and I'm trying to lear it ALL!!
this is my code written in "thisworkbook"
Private Sub Workbook_Open()
Call MyMacro
End Sub
This is my code in module1 (where my issue is):
Private dTime As Date
Sub MyMacro()
dTime = Now + TimeValue("00:00:03")
Application.OnTime dTime, "MyMacro"
Application.OnTime TimeValue("18:59:00"), "KPI_Screenshot"
Application.OnTime TimeValue("06:59:00"), "KPI_Screenshot"
If ActiveWorkbook.Name <> ThisWorkbook.Name Then Exit Sub
Calculate
Application.DisplayFullScreen = True
End Sub
This is my code for my screenshot to be embedded in an email body its located in module2:
Sub KPI_Screenshot()
Dim OutApp As Object
Dim OutMail As Object
On Error Resume Next
'Prepare the email
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = "exampleEmail@example.com"
.Subject = "Screen Shot"
.Display
bdy = "<img src='C:\Users\Example\Desktop\KPI Screenshots\test.jpg'>"
'Now add it into body
.HTMLBody = bdy
End With
On Error GoTo 0
OutApp.Session.Logoff
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
OK so here is my problem...I have a worksheet that displays production data on a TV monitor in the production office. This worksheet is generated by iHistorian tags and i have it set to update every 3 seconds (so we can see when equipment goes down, and the speed of the equipment "real time") I just created a macro that takes a screen shot of the report at the end of every shift (12 hour shift so they end at 7am and 7pm) then it saves the screen shot in a folder so it can be emailed out to everyone at the end of every shift (i still need help automating this screen shot to be embedded in the body of the email but that's another story) so to get to the point i added a application.ontime for this said screen shot and i dont know how to stop it after it takes the screen shot, so it takes a screen shot every 3 seconds....I need help!! thank you in advance!!!
(OH AND HOW DO YOU PUT CODE IN YOUR POST SO IT LOOKS LIKE REGULAR CODE INSTEAD OF PLAIN TEXT???)
Sorry i know this is a lot but you guys are awesome and I'm trying to lear it ALL!!
this is my code written in "thisworkbook"
Private Sub Workbook_Open()
Call MyMacro
End Sub
This is my code in module1 (where my issue is):
Private dTime As Date
Sub MyMacro()
dTime = Now + TimeValue("00:00:03")
Application.OnTime dTime, "MyMacro"
Application.OnTime TimeValue("18:59:00"), "KPI_Screenshot"
Application.OnTime TimeValue("06:59:00"), "KPI_Screenshot"
If ActiveWorkbook.Name <> ThisWorkbook.Name Then Exit Sub
Calculate
Application.DisplayFullScreen = True
End Sub
This is my code for my screenshot to be embedded in an email body its located in module2:
Sub KPI_Screenshot()
Dim OutApp As Object
Dim OutMail As Object
On Error Resume Next
'Prepare the email
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = "exampleEmail@example.com"
.Subject = "Screen Shot"
.Display
bdy = "<img src='C:\Users\Example\Desktop\KPI Screenshots\test.jpg'>"
'Now add it into body
.HTMLBody = bdy
End With
On Error GoTo 0
OutApp.Session.Logoff
Set OutMail = Nothing
Set OutApp = Nothing
End Sub