Power View Reports

Power View

Power View

O Power View é um novo recurso para análise, visualização e apresentação de dados presente a partir do Excel 2013 e do SharePoint 2010.

Tutorial: Create Amazing Power View Reports:

– Part 1

– Part 2

OBSERVAÇÃO : Aviso de Isenção de Tradução Automática: Este artigo foi traduzido por computador, sem intervenção humana. A Microsoft oferece essas traduções automáticas para ajudar as pessoas que não falam inglês a aproveitar os textos escritos sobre produtos, serviços e tecnologias da Microsoft. Como este artigo foi traduzido automaticamente, é possível que contenha erros de vocabulário, sintaxe ou gramática.

Importante : Power View e Power Pivot estão disponíveis nas edições do Office Professional Plus e Office 365 Professional Plus e na edição independente do Excel 2013. Leia as pastas de trabalho do Excel 2010 com PowerPivot não funcionam em algumas versões do Excel 201

 

Introdução ao Power View

O Power View tem duas versões:

As duas versões do Power View precisam do Silverlight instalado no computador.

Não é possível abrir um arquivo RDLX do Power View no Excel nem abrir um arquivo XLSX do Excel com planilhas do Power View no Power View no SharePoint. Você também não pode copiar gráficos ou outras visualizações do arquivo RDLX na pasta de trabalho do Excel.

Você pode salvar arquivos XLSX do Excel com planilhas do Power View no SharePoint Server, localmente ou no Office 365, e abrir esses arquivos no SharePoint. Leia mais sobre o Power View no Excel no SharePoint Server 2013 ou no SharePoint Online no Office 365.

Fontes de dados do Power View

No Excel 2013, você pode usar dados direto no Excel como a base para o Power View no Excel e no SharePoint. Quando você adiciona tabelas e cria relacionamentos entre elas, o Excel está criando um Modelo de dados nos bastidores. Um modelo de dados é uma coleção de tabelas e suas relações, refletindo as relações do mundo real entre funções e processos comerciais; por exemplo, a relação de Produtos com Inventário e Vendas. Você pode continuar modificando e aprimorando esse mesmo modelo de dados no PowerPivot no Excel, para criar um modelo de dados mais sofisticado para relatórios do Power View.

Com o Power View você pode interagir com os dados:

Início da Página

Criar gráficos e outras visualizações

No Power View, você pode criar rapidamente várias visualizações, de tabelas e matrizes a gráficos de pizza, barras e bolhas e conjuntos de gráficos de múltiplos. Para cada visualização a ser criada, inicie com uma tabela, que você poderá converter facilmente em outras visualizações, para localizar a que melhor ilustra os seus dados. Para criar uma tabela, clique em uma tabela ou em um campo na lista de campos ou arraste um campo da lista de campos para a exibição. O Power View desenha a tabela na exibição, exibindo os dados reais e adicionando automaticamente os títulos de coluna.

Para converter uma tabela em outras visualizações, clique em um tipo de visualização na guia Design. O Power View somente habilita os gráficos e outras visualizações que funcionam melhor para os dados nessa tabela. Por exemplo, se o Power View não detectar nenhum valor numérico agregado, nenhum gráfico será habilitado.

Leia mais sobre gráficos e outras visualizações de dados no Power View.

Início da Página

Filtrar e realçar dados

O Power View fornece vários modos de filtrar dados. O Power View usa os metadados no modelo de dados subjacente para entender as relações entre as diferentes tabelas e campos de uma pasta de trabalho ou relatório. Devido a essas relações, você pode usar uma visualização para filtrar e realçar todas as visualizações em uma planilha ou exibição. Ou você pode exibir a área de filtros e definir filtros que se aplicarão a uma visualização individual ou a todas as visualizações de uma planilha ou exibição. No Power View no SharePoint, você pode deixar o painel de filtro visível ou ocultá-lo antes de alternar para o modo de leitura ou de tela cheia.

Leia mais em Filtragem e realce no Power View.

Início da Página

Segmentações de dados

Segmentações de dados no Excel permitem comparar e avaliar seus dados de perspectivas diferentes. As segmentações de dados no Power View são semelhantes. Quando você tem várias segmentações de dados em uma exibição e seleciona uma entrada em uma segmentação de dados, essa seleção filtra as outras segmentações de dados na exibição.

Leia mais sobre segmentações de dados no Power View.

Classificação

Você pode classificar tabelas, matrizes, gráficos de barra e de coluna, e conjunto de pequenos múltiplos no Power View. Você classifica as colunas em tabelas e matrizes, as categorias ou valores numéricos em gráficos e os vários campos ou os valores numéricos em um conjunto de múltiplos. Em cada caso, você pode realizar a classificação em ordem crescente ou decrescente nos atributos, como Nome de Produto, ou nos valores numéricos, como Total de Vendas.

Leia mais em Classificação no Power View.

Início da Página

Relatórios com várias exibições no Power View no SharePoint

Um único relatório do Power View no SharePoint pode conter várias exibições. Todas as exibições em um relatório do Power View no SharePoint são baseadas no mesmo modelo tabular. Cada exibição tem suas próprias visualizações, e os filtros de cada exibição destinam-se somente a ela.

Leia mais em Relatórios com várias exibições no Power View no SharePoint.

OBSERVAÇÃO :  No Excel, cada planilha do Power View é uma planilha separada. Uma única pasta de trabalho do Excel pode conter qualquer número de planilhas do Power View e cada planilha do Power View pode ser baseada em um modelo diferente. Leia mais sobre Planilhas do Power View que se conectam a modelos de dados diferentes no Novidades no Power View no Excel 2013 e no SharePoint Server.

Início da Página

Compartilhar relatórios do Power View

Os relatórios do Power View são sempre apresentáveis – você pode procurar seus dados e apresentá-los a qualquer momento, porque está trabalhando com dados reais. Você não precisa visualizar o relatório para ver sua aparência.

Compartilhar o Power View no Excel

Compartilhe suas pastas de trabalho do Excel com planilhas do Power View:

Em um site do SharePoint Server 2013 ou no SharePoint Online.    Seja no local ou na nuvem, os leitores de relatório podem exibir e interagir com planilhas do Power View nas pastas de trabalho que você salvou.

Compartilhar o Power View em relatórios do SharePoint (arquivos RDLX)

Nos modos de apresentação de leitura e de tela inteira, a faixa de opções e outras ferramentas de design estão ocultas para fornecer mais espaço para as visualizações. O relatório ainda é totalmente interativo, com filtragem e recurso de realce.

Quando você cria relatórios do Power View no SharePoint, salva-os no SharePoint Server 2010 ou 2013, onde outros podem exibir e interagir com eles. Outros também podem editá-los e, dependendo de suas permissões no servidor, eles poderão salvar as suas alterações. Leia mais sobre criar, salvar e imprimir relatórios do Power View.

Você também pode exportar uma versão interativa de seu Power View no relatório do SharePoint para o PowerPoint. Cada modo de exibição no Power View se torna um slide separado do PowerPoint. A interação com relatórios do Power View exportados para o PowerPoint é semelhante à interação com modos de exibição de modos de leitura e de tela inteira do Power View: você interage com visualizações e filtros em cada modo de exibição, mas não pode criar visualizações nem filtros.

Leia sobre como exportar um relatório do Power View no SharePoint para o PowerPoint.

Início da Página

Imprimir relatórios do Power View

Os relatórios do Power View são projetados para interação, seja em arquivos XLSX do Excel ou arquivos RDLX no SharePoint: Você toca em valores em um gráfico e isso afeta os valores nos outros. Portanto, você pode imprimir uma planilha do Power View, mas ela é estática – não há interatividade no papel, claro.

Além disso, você cria um relatório do Power View para que ele tenha boa aparência na tela: Você ajusta todos os gráficos, tabelas e outros elementos visuais para caber em uma tela. Às vezes, um gráfico ou uma tabela tem uma barra de rolagem – o leitor precisa rolar para ver o restante dos valores desse gráfico ou tabela. Novamente, as barras de rolagem não funcionam no papel.

Definir propriedades de relatórios do Power View no Power Pivot

Você pode definir várias propriedades no Power Pivot para aprimorar a experiência com relatórios do Power View.

  • Selecione as agregações padrão
  • Defina o título, imagem e identificador padrão para cada tabela em seu modelo
  • Determine como os valores duplicados serão administrados nos relatórios do Power View
  • Ocultar tabelas, campos e medidas dos criadores de relatório do Power View
  • Defina os campos padrão do para uma tabela de modo que quando você clica em uma tabela no Power View, todos os campos padrão serão simultaneamente adicionados ao relatório

Início da Página

Desempenho

Para aprimorar o desempenho, o Power View recupera somente os dados necessários em um dado momento para uma visualização de dados. Desse modo, até mesmo se uma planilha ou exibição for baseada em um modelo de dados subjacente que contém milhões de linhas, o Power View buscará apenas os dados das linhas que estão visíveis na tabela em um momento específico. Se você arrastar a barra de rolagem para a parte inferior da tabela, verá que ela volta para que você possa rolar para baixo à medida que o Power View recupera mais linhas.

Início da Página

Comparar o Power View, o Construtor de Relatórios e o Designer de Relatórios

O Power View não substitui os produtos de relatório existentes do Reporting Services.

O Designer de Relatórios é um ambiente de design sofisticado que os desenvolvedores e profissionais de TI podem usar nos relatórios inseridos em seus aplicativos. No Designer de Relatórios, eles podem criar relatórios operacionais, fontes de dados compartilhadas, conjuntos de dados compartilhados e controles de visualizador de relatórios do autor.

No Construtor de Relatórios, os profissionais de TI e os usuários avançados podem criar relatórios operacionais sofisticados, partes de relatório reutilizáveis e conjuntos de dados compartilhados.

O Construtor de Relatórios e o Designer de Relatórios criam relatórios RDL; o Power View cria relatórios RDLX. O Power View não pode abrir relatórios RDL, e vice-versa.

OBSERVAÇÕES : Os relatórios RDL podem ser executados em servidores de relatórios no modo nativo do Reporting Services ou no modo do SharePoint.

Os relatórios RDLX do Power View pode ser executados apenas em servidores de relatórios no modo do SharePoint.

O Designer de Relatórios e o Construtor de Relatórios são enviados no SQL Server 2012 Service Pack 1 Reporting Services, junto com o Power View. Leia mais sobre as Ferramentas do SQL Server Reporting Services.

Início da Página

Mais sobre o Power View

Power View no Excel e no SharePoint

Novidades no Power View no Excel 2013 e no SharePoint Server

Tarefas de design básicas do Power View

Gráficos e outras visualizações no Power View

Filtrar e realçar no Power View

Hierarquias no Power View

Classificação no Power View

Alterar uma soma para uma média ou outra agregação no Power View

Formatar relatórios do Power View

Power View no Excel

Iniciar o Power View no Excel 2013

Relações no Power View

Atualizar os dados ou o modelo de dados de uma folha do Power View

Power View no Excel no SharePoint Server ou SharePoint Online no Office 365

Tutorial: otimizar o modelo de dados para geração de relatórios do Power View

Tutorial: criar um relatório do Power View com dados do Microsoft Azure Marketplace

Visualizando os eventos esportivos do verão de 2013 com o Power View no Excel 2013

Atalhos de teclado e acessibilidade no Power View no Excel

Power View no SharePoint

Requisitos do sistema para o Power View no SharePoint

Criar, salvar e imprimir relatórios do Power View no SharePoint

Relatórios com várias exibições no Power View no SharePoint

Objetos do modelo multidimensional no Power View

Atalhos de teclado e acessibilidade no Power View no SharePoint

 

OBSERVAÇÃO : Aviso de Isenção de Tradução Automática: Este artigo foi traduzido por computador, sem intervenção humana. A Microsoft oferece essas traduções automáticas para ajudar as pessoas que não falam inglês a aproveitar os textos escritos sobre produtos, serviços e tecnologias da Microsoft. Como este artigo foi traduzido automaticamente, é possível que contenha erros de vocabulário, sintaxe ou gramática.

 

Fontes:

Power View: explore, visualize e apresente seus dados

https://support.office.com/pt-br/article/Power-View-explore-visualize-e-apresente-seus-dados-98268d31-97e2-42aa-a52b-a68cf460472e

Declaring API Functions In 64 Bit Office

API

Introduction

With the introduction of Windows 7 and Office 2010 VBA developers face a new challenge: ensuring their applications work on both 32 bit and 64 bit platforms.

This page is meant to become the first stop for anyone who needs the proper syntax for his API declaration statement in Office VBA.

Many of the declarations were figured out by Charles Williams of www.decisionmodels.com when he created the 64 bit version of our Name Manager.

Links

Of course Microsoft documents how to do this. There is an introductory article on Microsoft MSDN:

Compatibility Between the 32-bit and 64-bit Versions of Office 2010

That article describes the how-to’s to properly write the declarations. What is missing is which type declarations go with which API function or sub.

Microsoft has provided an updated version of the Win32API.txt with all proper declarations available for download here:

Office 2010 Help Files: Win32API_PtrSafe with 64-bit Support

When you run the installer after downloading the file form the link above, it does not tell you where it installed the information. Look in this -new- folder on your C drive:

C:\Office 2010 Developer Resources\Documents\Office2010Win32API_PtrSafe

You can find a list of the old Win32 API declarations here:

Visual Basic Win32 API Declarations

Microsoft also published a tool to check your code for 64 bit related problems, called the Microsoft Office Code Compatibility inspector addin.

API functions that were added/modified in 64-bit Windows: http://msdn.microsoft.com/en-us/library/aa383663(VS.85).aspx

API Functions by Windows release:

http://msdn.microsoft.com/en-us/library/aa383687(VS.85).aspx

Utter Access API declarations (a comprehensive list of many declarations)

Last, but certainly not least: Dennis Walentin has built an API viewer that is really helpful. You can find the API viewer here.

Declarations by API function

Function name Declarations (32 bit followed by 64 bit)
CreateProcess We start off with a complicated one because it has a lot of arguments. A fully functional example is included below the example declaration lines.
Courtesy: The example code was taken from this page

     Declare Function CreateProcess Lib “kernel32” _
Alias “CreateProcessA” (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As SECURITY_ATTRIBUTES, _
lpThreadAttributes As SECURITY_ATTRIBUTES, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION)As LongDeclare PtrSafe Function CreateProcess Lib “kernel32” _
Alias “CreateProcessA” (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As SECURITY_ATTRIBUTES, _
lpThreadAttributes As SECURITY_ATTRIBUTES, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION)As LongPtr

‘Full example shown below, including the necessary structures
#If VBA7 Then
Declare PtrSafe Function CreateProcess Lib “kernel32” _
Alias “CreateProcessA” (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As SECURITY_ATTRIBUTES, _
lpThreadAttributes As SECURITY_ATTRIBUTES, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION)As LongPtrConst INFINITE = &HFFFF
Const STARTF_USESHOWWINDOW = &H1
Private Enum enSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End EnumPrivate Type PROCESS_INFORMATION
hProcess As LongPtr
hThread As LongPtr
dwProcessId As Long
dwThreadId As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As LongPtr
hStdOutput As LongPtr
hStdError As LongPtr
End Type

Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As LongPtr
bInheritHandle As Long
End Type

Private Enum enPriority_Class
NORMAL_PRIORITY_CLASS = &H20
IDLE_PRIORITY_CLASS = &H40
HIGH_PRIORITY_CLASS = &H80
End Enum
#Else
Declare Function CreateProcess Lib “kernel32” _
Alias “CreateProcessA” (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As SECURITY_ATTRIBUTES, _
lpThreadAttributes As SECURITY_ATTRIBUTES, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION)As Long

Const INFINITE = &HFFFF
Const STARTF_USESHOWWINDOW = &H1
Private Enum enSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

Private Enum enPriority_Class
NORMAL_PRIORITY_CLASS = &H20
IDLE_PRIORITY_CLASS = &H40
HIGH_PRIORITY_CLASS = &H80
End Enum
#End If

Private Function SuperShell(ByVal App As String, ByVal WorkDir As String, dwMilliseconds As Long, _
ByVal start_size As enSW, ByVal Priority_Class As enPriority_Class) AsBoolean

Dim pclass As Long
Dim sinfo As STARTUPINFO
Dim pinfo As PROCESS_INFORMATION
‘Not used, but needed
Dim sec1 As SECURITY_ATTRIBUTES
Dim sec2 As SECURITY_ATTRIBUTES
‘Set the structure size
sec1.nLength = Len(sec1)
sec2.nLength = Len(sec2)
sinfo.cb = Len(sinfo)
‘Set the flags
sinfo.dwFlags = STARTF_USESHOWWINDOW
‘Set the window’s startup position
sinfo.wShowWindow = start_size
‘Set the priority class
pclass = Priority_Class

‘Start the program
If CreateProcess(vbNullString, App, sec1, sec2, False, pclass, _
0&, WorkDir, sinfo, pinfo) Then
‘Wait
‘ WaitForSingleObject pinfo.hProcess, dwMilliseconds
SuperShell = True
Else
SuperShell = False
End If
End Function

Sub Test()
Dim sFile As String
‘Set the dialog’s title
sFile = Application.GetOpenFilename(“Executables (*.exe), *.exe”, , “”)
SuperShell sFile, Left(sFile, InStrRev(sFile, “\”)), 0, SW_NORMAL, HIGH_PRIORITY_CLASS
End Sub

FindWindow
Private Declare Function FindWindow Lib “USER32” Alias “FindWindowA” (ByVal lpClassName As String, ByVallpWindowName As String) As Long

Private
Declare PtrSafe Function FindWindow Lib “USER32” Alias “FindWindowA” (ByVal lpClassName AsString, ByVal lpWindowName As String) As LongPtr
FindWindowEx
Private Declare Function FindWindowEx Lib “USER32” _
Alias “FindWindowExA” (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPrivateDeclare PtrSafe Function FindWindowEx Lib “USER32” _
Alias “FindWindowExA” (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr
GdipCreateBitmapFromFile
Private Declare Function GdipCreateBitmapFromFile Lib “GDIPlus” (ByVal filename As Long, bitmap As Long)As Long
Private Declare PtrSafe Function GdipCreateBitmapFromFile Lib “GDIPlus” (ByVal filename As LongPtr, bitmap As LongPtr) As LongPtr
GdipCreateHBITMAPFromBitmap
Private Declare Function GdipCreateHBITMAPFromBitmap Lib “GDIPlus” (ByVal bitmap As Long, hbmReturn AsLong, ByVal background As Long) As Long
Private Declare PtrSafe Function GdipCreateHBITMAPFromBitmap Lib “GDIPlus” (ByVal bitmap As LongPtr, hbmReturn As LongPtr, ByVal background As Long) As LongPtr
GdipDisposeImage
Private Declare Function GdipDisposeImage Lib “GDIPlus” (ByVal image As Long) As Long
Private Declare PtrSafe Function GdipDisposeImage Lib “GDIPlus” (ByVal image As LongPtr) As LongPtr
GdiplusShutdown
Private Declare Function GdiplusShutdown Lib “GDIPlus” (ByVal token As Long) As Long
Private Declare PtrSafe Function GdiplusShutdown Lib “GDIPlus” (ByVal token As LongPtr) As LongPtr
GdiplusStartup
Private Declare Function GdiplusStartup Lib “GDIPlus” (token As Long, inputbuf As GdiplusStartupInput,Optional ByVal outputbuf As Long = 0) As Long
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Declare PtrSafe Function GdiplusStartup Lib “GDIPlus” (token As LongPtr, inputbuf AsGdiplusStartupInput, Optional ByVal outputbuf As LongPtr = 0) As LongPtrPrivate Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As LongPtr
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
GetClassName
Public Declare Function GetClassName Lib “USER32” Alias “GetClassNameA” _
(ByVal hWnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As LongPublic Declare PtrSafe Function GetClassName Lib “USER32” Alias “GetClassNameA” _
(ByVal hWnd As LongPtr, ByVal lpClassName As String, _
ByVal nMaxCount As LongPtr) As Long
GetDiskFreeSpaceEx
Private Declare Function GetDiskFreeSpaceEx Lib “kernel32” _
Alias “GetDiskFreeSpaceExA” (ByVal lpDirectoryName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long
Private Declare PtrSafe Function GetDiskFreeSpaceEx Lib “kernel32” Alias _
“GetDiskFreeSpaceExA” (ByVal lpDirectoryName As String, _
lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As _
Currency, lpTotalNumberOfFreeBytes As Currency) As LongPtr
getDC
Private Declare Function GetDC Lib “USER32” (ByVal hWnd As Long) As Long

Private
Declare PtrSafe Function GetDC Lib “USER32” (ByVal hWnd As LongPtr) As LongPtr
GetDesktopWindow
Public Declare Function GetDesktopWindow Lib “USER32” () As LongPublic Declare PtrSafe Function GetDesktopWindow Lib “USER32” () As LongPtr
getDeviceCaps
Private Declare Function GetDeviceCaps Lib “gdi32” (ByVal hDC As Long, ByVal nIndex As Long) As Long

Private
Declare PtrSafe Function GetDeviceCaps Lib “gdi32” (ByVal hDC As LongPtr, ByVal nIndex As Long)As Long
GetDriveType
Private Declare Function GetDriveType Lib “kernel32” Alias _
“GetDriveTypeA” (ByVal sDrive As String) As LongPrivate Declare PtrSafe Function GetDriveType Lib “kernel32” Alias _
“GetDriveTypeA” (ByVal sDrive As String) As LongPtr
GetExitCodeProcess
#If VBA7 Then
Declare PtrSafe Function GetExitCodeProcess Lib “kernel32” (ByVal _
hProcess As LongPtr, lpExitCode As Long) As Long
#Else
Declare Function GetExitCodeProcess Lib “kernel32” (ByVal _
hProcess As Long, lpExitCode As Long) As Long
#End If
GetForegroundWindow
Declare Function GetForegroundWindow Lib “user32.dll” () As LongDeclare PtrSafe Function GetForegroundWindow Lib “user32.dll” () As LongPtr
getFrequency
Declare Function getFrequency Lib “kernel32” Alias “QueryPerformanceFrequency” (cyFrequency As Currency)As Long

Private
Declare PtrSafe Function getFrequency Lib “kernel32” Alias “QueryPerformanceFrequency” (cyFrequency As Currency) As Long
GetKeyState
Declare Function GetKeyState Lib “USER32” (ByVal vKey As Long) As Integer

Declare
PtrSafe Function GetKeyState Lib “USER32” (ByVal vKey As Long) As Integer
GetLastInputInfo
#If VBA7 Then
Private Type LASTINPUTINFO
cbSize As LongPtr
dwTime As LongPtr
End Type
Private Declare PtrSafe Sub GetLastInputInfo Lib “USER32” (ByRef plii As LASTINPUTINFO)
#Else
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Private Declare Sub GetLastInputInfo Lib “USER32” (ByRef plii As LASTINPUTINFO)
#End If
GetOpenFileName
Option Explicit#If VBA7 Then
Public Declare PtrSafe Function GetOpenFileName Lib “comdlg32.dll” Alias _
“GetOpenFileNameA” (pOpenfilename As OPENFILENAME) As LongPublic Type OPENFILENAME
lStructSize As Long
hwndOwner As LongPtr
hInstance As LongPtr
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As LongPtr
lpTemplateName As String
End Type#Else

Public Declare Function GetOpenFileName Lib “comdlg32.dll” Alias _
“GetOpenFileNameA” (pOpenfilename As OPENFILENAME) As Long

Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
#End If
‘/////////////////////////////////
‘// End code GetOpenFileName    //
‘/////////////////////////////////

Public Function GetMyFile(strTitle As String) As String

Dim OpenFile    As OPENFILENAME
Dim lReturn     As Long

OpenFile.lpstrFilter = “”
OpenFile.nFilterIndex = 1
OpenFile.hwndOwner = 0
OpenFile.lpstrFile = String(257, 0)
#If VBA7 Then
OpenFile.nMaxFile = LenB(OpenFile.lpstrFile) – 1
OpenFile.lStructSize = LenB(OpenFile)
#Else
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) – 1
OpenFile.lStructSize = Len(OpenFile)
#End If
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = “C:\”
OpenFile.lpstrTitle = strTitle
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)

If lReturn = 0 Then
GetMyFile = “”
Else
GetMyFile = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) – 1))
End If

End Function

GetSystemMetrics
Private Declare Function GetSystemMetrics Lib “USER32” (ByVal nIndex As Long) As Long

Private
Declare PtrSafe Function GetSystemMetrics Lib “USER32” (ByVal nIndex As Long) As Long
GetTempPath
Declare Function GetTempPath Lib “kernel32” _
Alias “GetTempPathA” (ByVal nBufferLength As Long, _
ByVal lpbuffer As String) As LongDeclare PtrSafe Function GetTempPath Lib “kernel32” _
Alias “GetTempPathA” (ByVal nBufferLength As longptr, _
ByVal lpbuffer As String) As Long
getTickCount
Private Declare Function getTickCount Lib “kernel32” Alias “QueryPerformanceCounter” (cyTickCount AsCurrency) As Long

Private
Declare PtrSafe Function getTickCount Lib “kernel32” Alias “QueryPerformanceCounter” (cyTickCountAs Currency) As Long
getTime
Private Declare Function timeGetTime Lib “winmm.dll” () As Long

Private
Declare PtrSafe Function timeGetTime Lib “winmm.dll” () As Long
GetWindow
Public Declare Function GetWindow Lib “USER32” _
(ByVal hWnd As Long, ByVal wCmd As Long) As LongPublic Declare PtrSafe FunctionGetWindow Lib “USER32” _
(ByVal hWnd As LongPtr, ByVal wCmd As Long) As LongPtr
GetWindowLong This is one of the few API functions that requires the Win64 compile constant:

#If VBA7 Then
#If Win64 Then
Private Declare PtrSafe Function GetWindowLongPtr Lib “USER32” Alias “GetWindowLongPtrA” (ByValhWnd As LongPtr, ByVal nIndex As Long) As LongPtr
#Else
    Private Declare PtrSafe Function GetWindowLongPtr Lib “USER32” Alias “GetWindowLongA” (ByVal hWndAs LongPtr, ByVal nIndex As Long) As LongPtr
#End If
#Else
Private Declare Function GetWindowLongPtr Lib “USER32” Alias “GetWindowLongA” (ByVal hWnd As Long,ByVal nIndex As Long) As Long
#End If
GetWindowsDirectory
Declare Function GetWindowsDirectory& Lib “kernel32” Alias _
“GetWindowsDirectoryA” (ByVal lpbuffer As String, _
ByVal
nSize As Long)Declare PtrSafe Function GetWindowsDirectory& Lib “kernel32” Alias _
“GetWindowsDirectoryA” (ByVal lpbuffer As String, _
ByVal
nSize As LongPtr)
GetWindowText
Public Declare Function GetWindowText Lib “USER32” Alias “GetWindowTextA” _
(ByVal hWnd As Long, ByVal lpString As String, _
ByVal cch As Long) As LongPublic Declare PtrSafe Function GetWindowText Lib “USER32” Alias “GetWindowTextA” _
(ByVal hWnd As LongPtr, ByVal lpString As String, _
ByVal cch As LongPtr) As Long
InternetGetConnectedState
Public Declare Function InternetGetConnectedState _
Lib “wininet.dll” (lpdwFlags As Long, _
ByVal dwReserved As Long) As BooleanPublic Declare PtrSafe Function InternetGetConnectedState _
Lib “wininet.dll” (lpdwFlags As LongPtr, _
ByVal dwReserved As long) As Boolean
IsCharAlphaNumericA
Private Declare Function IsCharAlphaNumericA Lib “USER32” (ByVal byChar As Byte) As Long

Private
Declare PtrSafe Function IsCharAlphaNumericA Lib “USER32” (ByVal byChar As Byte) As Long
OleCreatePictureIndirect
Private Declare Function OleCreatePictureIndirect Lib “oleaut32.dll” (PicDesc As PICTDESC, RefIID AsGUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As LongPrivate Type PICTDESC
Size As Long
Type As Long
hPic As Long
hPal As Long
End Type
Private Declare PtrSafe Function OleCreatePictureIndirect Lib “oleaut32.dll” (PicDesc As PICTDESC, RefIIDAs GUID, ByVal fPictureOwnsHandle As LongPtr, IPic As IPicture) As LongPtrPrivate Type PICTDESC
Size As Long
Type As Long
hPic As LongPtr
hPal As LongPtr
End Type
OpenProcess
#If VBA7 Then
Declare PtrSafe Function OpenProcess Lib “kernel32” (ByVal _
dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal _
dwProcessId As Long) As LongPtr
#Else
Declare Function OpenProcess Lib “kernel32” (ByVal _
dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal _
dwProcessId As Long) As Long
#End If
ReleaseDC
Private Declare Function ReleaseDC Lib “USER32” (ByVal hWnd As Long, ByVal hDC As Long) As Long

Private
Declare PtrSafe Function ReleaseDC Lib “USER32” (ByVal hWnd As LongPtr, ByVal hDC As LongPtr) As Long
SendMessage
Public Declare Function SendMessageA Lib “user32” (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Declare PtrSafe Function SendMessageA Lib “user32” (ByVal hWnd As LongPtr, ByVal wMsg As Long, _
ByVal wParam As LongPtr, lParam As Any) As LongPtr
SetActiveWindow
Declare Function SetActiveWindow Lib “user32.dll” (ByVal hWnd As Long) As LongDeclare PtrSafe Function SetActiveWindow Lib “user32.dll” (ByVal hWnd As LongPtr) As LongPtr
SetCurrentDirectory
Private Declare Function SetCurrentDirectoryA Lib “kernel32” (ByVal lpPathName As String) As Long

Private
Declare PtrSafe Function SetCurrentDirectoryA Lib “kernel32” (ByVal lpPathName As String) As Long
SetWindowLongPtr This is one of the few API functions that requires the Win64 compile constant:

#If VBA7 Then
#If Win64 Then
Private Declare PtrSafe Function SetWindowLongPtr Lib “USER32” Alias “SetWindowLongPtrA” (ByValhWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
    Private Declare Function SetWindowLongPtr Lib “USER32” Alias “SetWindowLongA” (ByVal hWnd AsLongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
#Else
Private Declare Function SetWindowLongPtr Lib “USER32” Alias “SetWindowLongA” (ByVal hWnd As Long,ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If
SHBrowseForFolder
#If VBA7 Then
Private Type BROWSEINFO
hOwner As LongPtr
pidlRoot As LongPtr
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As LongPtr
lParam As LongPtr
iImage As Long
End TypePrivate Declare PtrSafe Function SHBrowseForFolder Lib “shell32.dll” Alias “SHBrowseForFolderA” _
(lpBrowseInfo As BROWSEINFO) As LongPtr
#Else
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End TypePrivate Declare Function SHBrowseForFolder Lib “shell32.dll” Alias “SHBrowseForFolderA” _
(lpBrowseInfo As BROWSEINFO) As Long
#End If
Private Const BIF_RETURNONLYFSDIRS = &H1
ShellExecute
Private Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” ( _
ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private
Declare PtrSafe Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” ( _
ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
SHFileOperation
#If VBA7 Then
Type SHFILEOPSTRUCT
hWnd As LongPtr
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Longptr
sProgress As String
End Type
Declare PtrSafe Function SHFileOperation Lib “shell32.dll” Alias “SHFileOperationA” _
(lpFileOp As SHFILEOPSTRUCT) As LongPtr
#Else
Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Declare Function SHFileOperation Lib “shell32.dll” Alias “SHFileOperationA” _
(lpFileOp As SHFILEOPSTRUCT) As Long
#End If
SHGetPathFromIDList
Private Declare Function SHGetPathFromIDList Lib “shell32.dll” Alias “SHGetPathFromIDListA” _
(ByVal pidl As Long, ByVal pszPath As String) As BooleanPrivate Declare PtrSafe Function SHGetPathFromIDList Lib “shell32.dll” Alias “SHGetPathFromIDListA” _
(ByVal pidl As LongPtr, ByVal pszPath As String) As Boolean
SHGetSpecialFolderLocation
    Private Declare Function SHGetSpecialFolderLocation Lib _
“shell32.dll” (ByVal hwndOwner As Long, ByVal nFolder As Long, _
pidl As ITEMIDLIST) As LongPrivate Declare PtrSafe Function SHGetSpecialFolderLocation Lib _
“shell32.dll” (ByVal hwndOwner As LongPtr, ByVal nFolder As Long, _
pidl As ITEMIDLIST) As LongPtr
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
timeGetTime
Private Declare Function timeGetTime Lib “winmm.dll” () As Long

Private
Declare PtrSafe Function timeGetTime Lib “winmm.dll” () As Long

Which Longs should become LongPtr?

It’s actually pretty easy to determine what requires LongPtr and what can stay as Long. The only things that require LongPtr are function arguments or return values that represent addresses in memory. This is because a 64-bit OS has a memory space that is too large to hold in a Long data type variable. Arguments or return values that represent data will still be declared Long even in 64-bit.

The SendMessage API is a good example because it uses both types:

32-bit:

Public Declare Function SendMessageA Lib “user32” (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

64 bit:

Public Declare PtrSafe Function SendMessageA Lib “user32” (ByVal hWnd As LongPtr, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As LongPtr

The first argument -hWnd- is a window handle, which is an address in memory. The return value is a pointer to a function, which is also an address in memory. Both of these must be declared LongPtr in 64-bit VBA. The arguments wMsg and wParam are used to pass data, so they can be Long in both 32-bit and 64-bit.

How to determine what is a memory address and what is data? You just have to read the MSDN documentation for the API functions (the C++ version) and it will tell you. Anything called a handle, pointer, brush or any other object type will require a LongPtr in 64-bit. Anything that is strictly data can stay as Long.

Conditional compiling

If your code needs to run on both 32 bit and 64 bit Excel, then another thing to do is add conditional compilation to your VBA.

Microsoft devised two compile constants to handle this:

VBA7: True if you’re using Office 2010, False for older versions

WIN64: True if your Office installation is 64 bit, false for 32 bit.

Since the 64 bit declarations also work on 32 bit Office 2010, all you have to test for is VBA7:

#If VBA7 Then
Private Declare PtrSafe Function GetDeviceCaps Lib “gdi32” (ByVal hDC As LongPtr, ByVal nIndex As Long) As Long
#Else
Private Declare Function GetDeviceCaps Lib “gdi32” (ByVal hDC As Long, ByVal nIndex As Long) As Long
#End If

And then in the routine where this function is put to use:

#If VBA7 Then
Dim hDC As LongPtr
#Else
Dim hDC As Long
#End If
Dim lDotsPerInch As Long
‘Get the user’s DPI setting
lDotsPerInch = GetDeviceCaps(hDC, LOGPIXELSX)

Other API functions

Have a function declaration which is not on this list? I invite you to send me your (working and tested!!!) declarations so I can add them here.

I also welcome comments and suggestions on improvements!

 

Autor

JKP – Application Development Services

http://www.jkp-ads.com/articles/apideclarations.asp

 

 

Fale Conosco