Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA macro to obtain file names using WIN32 API
I have a problem trying to get an Excel VBA macro to use a Win32 API
function. In the macro, I defined the variable structBuffer in the Declarations section as; Type WIN32_FIND_FILE_DATA FileAttributes As Long CreationTime As String AccessTime As String WriteTime As String SizeHigh As Long SizeLow As Long Reserved0 As Long Reserved1 As Long FileName As String FileAltName As String * 14 End Type to match the Win32 struct which is defined as; typedef struct _WIN32_FIND_DATA { // wfd DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[ MAX_PATH ]; TCHAR cAlternateFileName[ 14 ]; } WIN32_FIND_DATA; and I defined the Win32 API function FindFirstFile() like this; Declare Function FindFirstFile Lib "kernel32" _ Alias "FindFirstFileA" (ByVal lpFileName As String, _ lpFindFileData As WIN32_FIND_FILE_DATA) _ As Long I define the structBuffer variable like this; Dim stuctBuffer As WIN32_FIND_FILE_DATA I have these two lines in the macro. strFullPath = strPath & "\*.*" lnHandle = FindFirstFile(strFullPath, structBuffer) strPath is the drive and directory path to the Temporary Internet Files directory (that holds cookies, shortcuts, etc). When I try to run the macro, it flags this line lnHandle = FindFirstFile(strFullPath, structBuffer) as a Compile error: ByRef argument type mismtach as it highlights structBuffer. I don't understand what I have done wrong. I'm sure I'm on the right track here so hopefully it's something quite simple. I have been using the VBA Dir() function to obtain file names in other directories but the Temporary Internet Files directory returns nothing to the Dir() function. A DIR command at the command prompt in this directory also shows nothing, but Windows Explorer is quite capable of listing all the cookies, URLs etc that fill up this directory. This is why I am trying to use the Win32 API instead of the VBA functions. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA macro to obtain file names using WIN32 API
According to my reading of the typedef structure, the
Type WIN32_FIND_FILE_DATA FileAttributes As Long CreationTime As String AccessTime As String WriteTime As String SizeHigh As Long SizeLow As Long Reserved0 As Long Reserved1 As Long FileName As String FileAltName As String * 14 End Type should be Type WIN32_FIND_FILE_DATA FileAttributes As Long CreationTime As FILETIME AccessTime As FILETIME WriteTime As FILETIME SizeHigh As Long SizeLow As Long Reserved0 As Long Reserved1 As Long FileName As String FileAltName As String * 14 End Type with FILETIME defined as another structure aka Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Mudd" wrote in message ... I have a problem trying to get an Excel VBA macro to use a Win32 API function. In the macro, I defined the variable structBuffer in the Declarations section as; Type WIN32_FIND_FILE_DATA FileAttributes As Long CreationTime As String AccessTime As String WriteTime As String SizeHigh As Long SizeLow As Long Reserved0 As Long Reserved1 As Long FileName As String FileAltName As String * 14 End Type Private Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH Accordin cAlternate As String * 14 End Type to match the Win32 struct which is defined as; typedef struct _WIN32_FIND_DATA { // wfd DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[ MAX_PATH ]; TCHAR cAlternateFileName[ 14 ]; } WIN32_FIND_DATA; and I defined the Win32 API function FindFirstFile() like this; Declare Function FindFirstFile Lib "kernel32" _ Alias "FindFirstFileA" (ByVal lpFileName As String, _ lpFindFileData As WIN32_FIND_FILE_DATA) _ As Long I define the structBuffer variable like this; Dim stuctBuffer As WIN32_FIND_FILE_DATA I have these two lines in the macro. strFullPath = strPath & "\*.*" lnHandle = FindFirstFile(strFullPath, structBuffer) strPath is the drive and directory path to the Temporary Internet Files directory (that holds cookies, shortcuts, etc). When I try to run the macro, it flags this line lnHandle = FindFirstFile(strFullPath, structBuffer) as a Compile error: ByRef argument type mismtach as it highlights structBuffer. I don't understand what I have done wrong. I'm sure I'm on the right track here so hopefully it's something quite simple. I have been using the VBA Dir() function to obtain file names in other directories but the Temporary Internet Files directory returns nothing to the Dir() function. A DIR command at the command prompt in this directory also shows nothing, but Windows Explorer is quite capable of listing all the cookies, URLs etc that fill up this directory. This is why I am trying to use the Win32 API instead of the VBA functions. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA macro to obtain file names using WIN32 API
Perhaps you want to look at this article:
http://support.microsoft.com/default...76&Product=vbb How To Search Directories to Find or List Files -- Regards, Tom Ogilvy "Mudd" wrote in message ... I have a problem trying to get an Excel VBA macro to use a Win32 API function. In the macro, I defined the variable structBuffer in the Declarations section as; Type WIN32_FIND_FILE_DATA FileAttributes As Long CreationTime As String AccessTime As String WriteTime As String SizeHigh As Long SizeLow As Long Reserved0 As Long Reserved1 As Long FileName As String FileAltName As String * 14 End Type to match the Win32 struct which is defined as; typedef struct _WIN32_FIND_DATA { // wfd DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[ MAX_PATH ]; TCHAR cAlternateFileName[ 14 ]; } WIN32_FIND_DATA; and I defined the Win32 API function FindFirstFile() like this; Declare Function FindFirstFile Lib "kernel32" _ Alias "FindFirstFileA" (ByVal lpFileName As String, _ lpFindFileData As WIN32_FIND_FILE_DATA) _ As Long I define the structBuffer variable like this; Dim stuctBuffer As WIN32_FIND_FILE_DATA I have these two lines in the macro. strFullPath = strPath & "\*.*" lnHandle = FindFirstFile(strFullPath, structBuffer) strPath is the drive and directory path to the Temporary Internet Files directory (that holds cookies, shortcuts, etc). When I try to run the macro, it flags this line lnHandle = FindFirstFile(strFullPath, structBuffer) as a Compile error: ByRef argument type mismtach as it highlights structBuffer. I don't understand what I have done wrong. I'm sure I'm on the right track here so hopefully it's something quite simple. I have been using the VBA Dir() function to obtain file names in other directories but the Temporary Internet Files directory returns nothing to the Dir() function. A DIR command at the command prompt in this directory also shows nothing, but Windows Explorer is quite capable of listing all the cookies, URLs etc that fill up this directory. This is why I am trying to use the Win32 API instead of the VBA functions. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA macro to obtain file names using WIN32 API
I have made the change in the typedef as described but I still get the
compile error for the structBuffer argument. Bob Phillips wrote in message ... According to my reading of the typedef structure, the Type WIN32_FIND_FILE_DATA FileAttributes As Long CreationTime As String AccessTime As String WriteTime As String SizeHigh As Long SizeLow As Long Reserved0 As Long Reserved1 As Long FileName As String FileAltName As String * 14 End Type should be Type WIN32_FIND_FILE_DATA FileAttributes As Long CreationTime As FILETIME AccessTime As FILETIME WriteTime As FILETIME SizeHigh As Long SizeLow As Long Reserved0 As Long Reserved1 As Long FileName As String FileAltName As String * 14 End Type with FILETIME defined as another structure aka Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Mudd" wrote in message ... I have a problem trying to get an Excel VBA macro to use a Win32 API function. In the macro, I defined the variable structBuffer in the Declarations section as; Type WIN32_FIND_FILE_DATA FileAttributes As Long CreationTime As String AccessTime As String WriteTime As String SizeHigh As Long SizeLow As Long Reserved0 As Long Reserved1 As Long FileName As String FileAltName As String * 14 End Type Private Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH Accordin cAlternate As String * 14 End Type to match the Win32 struct which is defined as; typedef struct _WIN32_FIND_DATA { // wfd DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[ MAX_PATH ]; TCHAR cAlternateFileName[ 14 ]; } WIN32_FIND_DATA; and I defined the Win32 API function FindFirstFile() like this; Declare Function FindFirstFile Lib "kernel32" _ Alias "FindFirstFileA" (ByVal lpFileName As String, _ lpFindFileData As WIN32_FIND_FILE_DATA) _ As Long I define the structBuffer variable like this; Dim stuctBuffer As WIN32_FIND_FILE_DATA I have these two lines in the macro. strFullPath = strPath & "\*.*" lnHandle = FindFirstFile(strFullPath, structBuffer) strPath is the drive and directory path to the Temporary Internet Files directory (that holds cookies, shortcuts, etc). When I try to run the macro, it flags this line lnHandle = FindFirstFile(strFullPath, structBuffer) as a Compile error: ByRef argument type mismtach as it highlights structBuffer. I don't understand what I have done wrong. I'm sure I'm on the right track here so hopefully it's something quite simple. I have been using the VBA Dir() function to obtain file names in other directories but the Temporary Internet Files directory returns nothing to the Dir() function. A DIR command at the command prompt in this directory also shows nothing, but Windows Explorer is quite capable of listing all the cookies, URLs etc that fill up this directory. This is why I am trying to use the Win32 API instead of the VBA functions. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro recorded... tabs & file names changed, macro hangs | Excel Worksheet Functions | |||
Macro File Names | Excel Worksheet Functions | |||
Macro File Names | Excel Worksheet Functions | |||
Cant open Execl file-Not a valid win32 Application | Excel Discussion (Misc queries) | |||
Not a valid Win32 file ? | Setting up and Configuration of Excel |