Moderatori: Anthony47, Flash30005
Sub Prepara()
Application.OnTime Sheets("Orari").Range("A2").Value, "Messaggia"
End Sub
Sub messaggia()
Beep
MsgBox ("Beep...")
End Sub
Option Explicit
Private Sub Workbook_Open() ' mettere in "questa cartella di lavoro"
Dim Wb As Workbook
Dim myOre As String
Dim Sh1 As Worksheet
Dim Sh2 As Worksheet
Dim COra As Date
Dim mysec As Date
Dim cell As Range
Dim mySh As String
Application.DecimalSeparator = "."
Application.ThousandsSeparator = ","
Application.UseSystemSeparators = False
Set Wb = Workbooks("06AA_2020_AzioniITA_Auto_Storico .xlsm") '<<<correggere con propri riferimenti
Set Sh1 = Sheets("Orari") ' <<< Il Foglio che contiene myOre <<<correggere idem
myOre = "A2:A10" ' <<< L' area in cui sono elencati gli orari di esecuzione idem
mySh = "Orari"
Sh1.Activate
Application.ScreenUpdating = False
Sh1.Range("A2:A10").Interior.ColorIndex = xlColorIndexNone
mysec = Timer / 10
COra = 10 * TimeSerial(0, 0, mysec + 1)
For Each cell In Sh1.Range("A2:A10")
If cell.Value > COra Then
Application.OnTime (cell.Value), "Riesegui"
cell.Interior.ColorIndex = 4
Exit For
End If
Next cell
Set Wb = Nothing
Set Sh1 = Nothing
End Sub
Option Explicit
Sub Riesegui() ' in un modulo
Dim Wb As Workbook
Dim myOre As String
Dim Sh1 As Worksheet
Dim COra As Date
Dim cell As Range
Dim mySh As String
Dim mysec As Date
Set Wb = Workbooks("06AA_2020_AzioniITA_Auto_Storico .xlsm") '<<<correggere
Set Sh1 = Sheets("Orari") '<<<correggere
Sh1.Activate
Call Copiaweb '<<<< correggere con propria macro da attivare
'MsgBox "Ok"
'Pianifica la prossima esecuzione:
myOre = "A2:A10" '<<< L' area in cui sono elencati gli orari di esecuzione
mySh = "Orari" '<<< Il Foglio che contiene myOre
Sh1.Range(myOre).Interior.ColorIndex = xlNone
mysec = Timer / 10
COra = 10 * TimeSerial(0, 0, mysec + 1)
For Each cell In Wb.Sheets("Orari").Range(myOre)
If cell.Value > COra Then
Application.OnTime (cell.Value), "Riesegui"
cell.Interior.ColorIndex = 4
Exit For
End If
Next cell
'**
End Sub
Public Sub chiudi_excel()
ActiveWorkbook.Save
With Application
.DisplayAlerts = False
ActiveWorkbook.Close
.DisplayAlerts = True
End With
' qui vorrei aggiungere anche la chiusura dell'icona precedentemente aperta "Insomnia.exe" con la shell vedi sotto
End Sub
Sub carica() ' attiva programma Insommnia
Dim Programma As String
Dim Wb As Workbook
Dim Uriga As Long
Dim rn As Range
Dim Sh1 As Worksheet
Set Wb = Workbooks("FTSEMIB_Storico3 .xlsm") '<<<correggere
Set Sh1 = Sheets("Orari") '<<<correggere
Sh1.Activate
Uriga = Range("a2:a21").Cells.Count - Application.WorksheetFunction.CountIf(Range("A2:a21"), "")
If Uriga = 0 Then Exit Sub
If Uriga >= 1 Then
Programma = "C:\Sveglia_PC\Insomnia.exe" 'Da modificare col proprio percorso
'Shell Programma, vbNormalFocus ' icona normale
Shell Programma, vbMinimizedFocus ' minimizza sulla tray
End If
End Sub
Shell Programma, vbNormalFocus ' icona normale
Shell Programma, vbMinimizedFocus ' minimizza sulla tray bar
Public Sub chiudi_excel()
Application.DisplayAlerts = False
ThisWorkbook.Save
TerminateProcess
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
Sub TerminateProcess()
'---------------------------------------------------------------------------------------
' : Terminates a process. First checking to see if it is running or not.
' : Uses WMI (Windows Management Instrumentation) to query all running processes
' : then terminates ALL instances of the specified process
' : held in the variable strTerminateThis.
' :
' : ***WARNING: This will terminate a specified running process,use with caution!.
' : ***Terminating certain processes can effect the running of Windows and/or
' : ***running applications.
'---------------------------------------------------------------------------------------
Dim strTerminateThis As String 'The variable to hold the process to terminate
Dim objWMIcimv2 As Object
Dim objProcess As Object
Dim objList As Object
Dim intError As Integer
Dim pausa As Long
Dim oraattuale As Date
strTerminateThis = "Insomnia.exe" 'Process to terminate,
'change notepad.exe to the process you want to terminate
Set objWMIcimv2 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2") 'Connect to CIMV2 Namespace
Set objList = objWMIcimv2.ExecQuery _
("select * from win32_process where name='" & strTerminateThis & "'") 'Find the process to terminate
If objList.Count = 0 Then 'If 0 then process isn't running
MsgBox strTerminateThis & " is NOT running." & vbCr & vbCr _
& "Exiting procedure.", vbCritical, "Unable to continue"
Set objWMIcimv2 = Nothing
Set objList = Nothing
Set objProcess = Nothing
Exit Sub
ElseIf objList.Count <> 0 Then
''Ask if OK to continue
'Select Case MsgBox("Are you sure you want to terminate this running process?:" _
' & vbCrLf & "" _
' & vbCrLf & "Process name: " & strTerminateThis _
' & vbCrLf & "" _
' & vbCrLf & "Note:" _
' & vbCrLf & "Terminating certain processes can effect the running of Windows" _
' & "and/or running applications. The process will terminate if you OK it, WITHOUT " _
' & "giving you the chance to save any changes in anything that is running in the specified process above." _
' , vbOKCancel Or vbQuestion Or vbSystemModal Or vbDefaultButton1, "WARNING:")
' Case vbOK
'OK to continue with terminating the process
For Each objProcess In objList
intError = objProcess.Terminate 'Terminates a process and all of its threads.
'Return value is 0 for success. Any other number is an error.
If intError <> 0 Then
MsgBox "ERROR: Unable to terminate that process.", vbCritical, "Aborting"
Exit Sub
End If
Next
'ALL instances of specified process (strTerminateThis) has been terminated
'Call MsgBox("ALL instances of process " & strTerminateThis & " has been successfully terminated.", _
'vbInformation, "Process Terminated")
Set objWMIcimv2 = Nothing
Set objList = Nothing
Set objProcess = Nothing
Exit Sub
Else
'Else: vbCancel
'Case vbCancel
'NOT OK to continue with the termination, abort
Set objWMIcimv2 = Nothing
Set objList = Nothing
Set objProcess = Nothing
Exit Sub
' End Select
End If
pausa = 10
oraattuale = Timer
Do While Timer < oraattuale + pausa
DoEvents
Loop
End Sub
Torna a Applicazioni Office Windows
Macro modifica date scelta periodo Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 11 |
Supporto per sviluppo macro VBA Ordinare per data Autore: Carletto Ribolla |
Forum: Applicazioni Office Windows Risposte: 3 |
Macro per aprire file salvato su sharepoint Onedrive Autore: marcopont |
Forum: Applicazioni Office Windows Risposte: 2 |
Come interrompere macro sndPlaySound Autore: systemcrack |
Forum: Applicazioni Office Windows Risposte: 2 |
Visitano il forum: Nessuno e 24 ospiti