I am fairly new to VBA but have been having a play. I am trying to list the contents of the folder, via a msgbox, in a spreadsheet macro. This should work wherever the spreadsheet is placed. I have the macro below and all works fine when I first create it. The folder it is created in is listed off nicely, I can delete files, add files and rename files and all is reported back as I would like. But if I move the spreadsheet to another directory it just seems to list the contents of My Documents?
I have used the FSO because I want to take this macro and copy some rows from a load of other worksheets but I think I might have that bit sussed once I can achieve the moving of the workbook and the macro still working.
Is there something glaring out at you that I have missed.
Cheech
[Peace][Pipe]
Code:
Sub getFiles()
'
'
Fold = (ActiveWorkbook.Path)
Dim fso
Set fso = CreateObject("Scripting.FilesystemObject")
Set cpFolder = fso.GetFolder(Fold)
Set fylist = cpFolder.Files
For Each fyle In fylist
If fyle.Name <> "myFile.xls" Then
msg = msg & fyle.Name & vbNewLine
End If
Next
If msg = "" Then
msg = "No Files"
End If
MsgBox (msg)
'
End Sub
I have used the FSO because I want to take this macro and copy some rows from a load of other worksheets but I think I might have that bit sussed once I can achieve the moving of the workbook and the macro still working.
Is there something glaring out at you that I have missed.
Cheech
[Peace][Pipe]