¿Donde se declaran las bariables las PUBLIC TYPE?
Publicado por fenix (47 intervenciones) el 25/03/2008 20:57:28
¿Donde se declaran las bariables las PUBLIC TYPE?
Este codigo lo encontre y entiendo que que para leer carpetas. Pero me da un error en el
Public Type BROWSEINFO. Envia el siguiente msg "No se puede definir un tipo definido por el usuario Public dentro de un modulo de objeto".
Gracias
Option Explicit
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public 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 Type
Sub ListFiles()
Dim Msg As String
Dim Directory As String
Dim R As Long, X As Long
Dim C As Long
Application.StatusBar = "Esta macro puede tardar varios minutos"
Msg = "Selecciona el directorio que contiene los Ficheros Necesarios:"
Directory = GetDirectory(Msg)
If Directory = "" Then Exit Sub
If Right(Directory, 1) <> "" Then Directory = Directory & ""
R = Cells(65536, Range("PTSOurce").Cells(1).Column).End(xlUp).Offset(1, 0).Row
C = Range("PTSOurce").Cells(1).Column
On Error Resume Next
With Application.FileSearch
.NewSearch
.LookIn = Directory
If Range("Extension").Value = "" Then
.Filename = "*.*"
Else
.Filename = "*." & Range("Extension").Value
End If
If LCase(Range("SubFicheros").Value) = "si" Then
.SearchSubFolders = True
Else
.SearchSubFolders = False
End If
.Execute
For X = 1 To .FoundFiles.Count
Cells(R, C) = Application.WorksheetFunction.RoundDown((FileLen(.FoundFiles(X)) / 1048656.21374046), 0) '1048656 '1000
Cells(R, C + 1) = .FoundFiles(X)
Cells(R, C + 2) = Mid(.FoundFiles(X), Len(Directory) + 1) ', Len(Directory))
R = R + 1
If R > 65500 Then Exit For
Next X
End With
Application.StatusBar = ""
MsgBox "Listo"
End Sub
Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim Path As String
Dim R As Long
Dim X As Long
Dim pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = Msg
End If
bInfo.ulFlags = &H1
X = SHBrowseForFolder(bInfo)
Path = Space$(512)
R = SHGetPathFromIDList(ByVal X, ByVal Path)
If R Then
pos = InStr(Path, Chr$(0))
GetDirectory = Left(Path, pos - 1)
Else
GetDirectory = ""
End If
End Function
Sub Borrar()
Dim Rg As Range
Set Rg = ActiveSheet.Range("PTSource").CurrentRegion
Set Rg = Rg.Offset(1, 0)
Rg.ClearContents
End Sub
Este codigo lo encontre y entiendo que que para leer carpetas. Pero me da un error en el
Public Type BROWSEINFO. Envia el siguiente msg "No se puede definir un tipo definido por el usuario Public dentro de un modulo de objeto".
Gracias
Option Explicit
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public 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 Type
Sub ListFiles()
Dim Msg As String
Dim Directory As String
Dim R As Long, X As Long
Dim C As Long
Application.StatusBar = "Esta macro puede tardar varios minutos"
Msg = "Selecciona el directorio que contiene los Ficheros Necesarios:"
Directory = GetDirectory(Msg)
If Directory = "" Then Exit Sub
If Right(Directory, 1) <> "" Then Directory = Directory & ""
R = Cells(65536, Range("PTSOurce").Cells(1).Column).End(xlUp).Offset(1, 0).Row
C = Range("PTSOurce").Cells(1).Column
On Error Resume Next
With Application.FileSearch
.NewSearch
.LookIn = Directory
If Range("Extension").Value = "" Then
.Filename = "*.*"
Else
.Filename = "*." & Range("Extension").Value
End If
If LCase(Range("SubFicheros").Value) = "si" Then
.SearchSubFolders = True
Else
.SearchSubFolders = False
End If
.Execute
For X = 1 To .FoundFiles.Count
Cells(R, C) = Application.WorksheetFunction.RoundDown((FileLen(.FoundFiles(X)) / 1048656.21374046), 0) '1048656 '1000
Cells(R, C + 1) = .FoundFiles(X)
Cells(R, C + 2) = Mid(.FoundFiles(X), Len(Directory) + 1) ', Len(Directory))
R = R + 1
If R > 65500 Then Exit For
Next X
End With
Application.StatusBar = ""
MsgBox "Listo"
End Sub
Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim Path As String
Dim R As Long
Dim X As Long
Dim pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = Msg
End If
bInfo.ulFlags = &H1
X = SHBrowseForFolder(bInfo)
Path = Space$(512)
R = SHGetPathFromIDList(ByVal X, ByVal Path)
If R Then
pos = InStr(Path, Chr$(0))
GetDirectory = Left(Path, pos - 1)
Else
GetDirectory = ""
End If
End Function
Sub Borrar()
Dim Rg As Range
Set Rg = ActiveSheet.Range("PTSource").CurrentRegion
Set Rg = Rg.Offset(1, 0)
Rg.ClearContents
End Sub
Valora esta pregunta


0