Propósito

✔ Programação GLOBAL® - Quaisquer soluções e/ou desenvolvimento de aplicações pessoais, ou da empresa, que não constem neste Blog devem ser tratados como consultoria freelance. Queiram contatar-nos: brazilsalesforceeffectiveness@gmail.com | ESTE BLOG NÃO SE RESPONSABILIZA POR QUAISQUER DANOS PROVENIENTES DO USO DOS CÓDIGOS AQUI POSTADOS EM APLICAÇÕES PESSOAIS OU DE TERCEIROS.

.: Vitrine

Carregando artigos...

Views

Mostrando postagens com marcador kernel32. Mostrar todas as postagens
Mostrando postagens com marcador kernel32. Mostrar todas as postagens

VBA Tips - Demonstrar o tempo em Milisegundos - How to Get Time in Milliseconds using VBA


Saber expressar o tempo em milisegundos pode ser importante em qualquer  aplicação VBA. Como fazê-lo?

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Declare Sub GetSystemTime Lib "kernel32" _
(lpSystemTime As SYSTEMTIME)

Public Function TimeToMillisecond() As String
Dim tSystem As SYSTEMTIME
Dim sRet
On Error Resume Next
GetSystemTime tSystem
sRet = Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & _
":" & tSystem.wMilliseconds
TimeToMillisecond = sRet
End Function

Tags: Tips, milisegundos, miliseconds, API, LIB, kernel32, DLL, time, VBA, 

VBA Excel Basics - Modo profissional de Abrir e Fechar o MS Excel


O objeto Application do MS Excel disponibiliza uma coleção de objetos para controle das janelas (Windows) que permitem que abramos, organizemos, redimensionemos e fechemos as janelas filhas (child) do MS Excel.

 O código abaixo abrirá uma nova janela filha e colocará as janelas em cascata, abrindo as janelas para a pasta de trabalho ativa:

Sub OpenCascadeWindows()
    ActiveWindow.NewWindow
    Application.Windows.Arrange xlArrangeStyleCascade, True
End Sub

Feche a janela aberta no código anterior e restaure a janela original para um estado maximizado no Excel:

Sub CloseMaximize()
    ActiveWindow.Close
    ActiveWindow.WindowState = xlMaximized
End Sub

Controle a janela pai do MS Excel usando as propriedades WindowState e DisplayFullScreen do objeto Application

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub ChangeExcelWindowState()
    Let Application.WindowState = xlMaximized
    Sleep 1000

    Let Application.WindowState = xlMinimized
    Sleep 1000

    Let Application.WindowState = xlNormal
    Sleep 1000

    Let Application.DisplayFullScreen = True
    Sleep 1000

    Let Application.DisplayFullScreen = False
End Sub

Tags: VBA, Excel, Basics, open, close, window, DisplayFullScree, WindowState, application, Kernel32, LIB, API, 


VBA - Retornando nome de usuário logado na máquina.

Cole o código abaixo em um novo módulo e faça referência a atcNames: ? "User: " & atCNames(1) & "- " & Trim(atCNames(2)), Now() Private Declare Function api_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Declare Function api_GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Public Function atCNames(UOrC As Integer) As String ' Author: Date: Contact: ' André Bernardes 06/06/2009 07:23 bernardess@gmail.com ' . 'Purpose: Returns the User LogOn Name or ComputerName 'Accepts: UorC; 1=User, anything else = computer 'Returns: The Windows Networking name of the user or computer On Error Resume Next Dim NBuffer As String Dim Buffsize As Long Dim Wok As Long Let Buffsize = 256 Let NBuffer = Space$(Buffsize) If UOrC = 1 Then Let Wok = api_GetUserName(NBuffer, Buffsize) Let atCNames = Trim$(NBuffer) Else Let Wok = api_GetComputerName(NBuffer, Buffsize) Let atCNames = Trim$(NBuffer) End If End Function
André Luiz Bernardes
diHITT - Notícias