Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro File Names John Excel Worksheet Functions 2 December 5th 08 06:27 AM
Macro File Names John Excel Worksheet Functions 1 December 5th 08 06:23 AM
Cant open Execl file-Not a valid win32 Application Albert Excel Discussion (Misc queries) 0 August 10th 08 08:34 AM
Not a valid Win32 file ? davestanyon Setting up and Configuration of Excel 0 May 9th 05 05:54 PM


All times are GMT +1. The time now is 06:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"