Views

Histats

Vitrine

Access 2016 - Função Shell

Access 2016 - Função Shell


Aprenda a abrir e fechar um arquivo com a função VBA Shell.

Sub OpenClose()
'Open and Close a File
Dim vPID As Variant
'Launch file
vPID = Shell("notepad.exe ""C:\VBA\text.txt""", vbNormalFocus)

'Perform your actions here

'Kill file
Call Shell("TaskKill /F /PID " & CStr(vPID), vbHide)

End Sub

Antes de lhe mostrar como personalizar a função Shell, quero que saiba que existem diversas maneiras de invocá-la.

A seguir demonstro todas as formas possíveis para se executar o aplicativo Timer. Perceba que que a função Shell retorna um valor Double.

Sub DailyTimer()
'Run timer
Dim vPID As Variant
'Variation 1:
vPID = Shell("wscript.exe ""C:\VBScripts\Timer.vbs""", vbNormalFocus)
'Variation 2:
Shell "explorer.exe ""C:\VBScripts\Timer.vbs""", 1
'Variation 3:
Call Shell("Explorer.exe ""C:\VBScripts\Timer.vbs""", vbNormalFocus)
'Variation 4 - Open with Notepad for Editing:
vPID = Shell("notepad.exe ""C:\VBScripts\Timer.vbs""", vbNormalFocus)
End Sub

Outro exemplo:

dTimer=InputBox("Enter timer interval in minutes","Set Timer") 'minutes

do until IsNumeric(dTimer)=True
  dTimer=InputBox("Invalid Entry" & vbnewline & vbnewline & _ 
         "Enter timer interval in minutes","Set Timer") 'minutes
loop

if dTimer<>"" then
do
  WScript.Sleep dTimer*60*1000 'convert from minutes to milliseconds
  t=MsgBox("Take a Walk." & vbnewline & vbnewline & "Restart Timer?", _
    vbYesNo, "It's been " & dTimer &" minute(s)")
  if t=6 then 'if yes
       'continue loop
  else 'exit loop
       exit do
  end if
loop
end if


Aplicável em: Access 2016, Access 2013, Access 2010, Access 2007, 


brazilsalesforceeffectiveness@gmail.com


✔ Brazil SFE®Author´s Profile  Google+   Author´s Professional Profile   Pinterest   Author´s Tweets




✔ VBA Brazil®

✔ VBA Brazil®
brazilsalesforceeffectiveness@gmail.com
Related Posts Plugin for WordPress, Blogger...
diHITT - Notícias