Pinaceous
Well-known Member
- Joined
- Jun 11, 2014
- Messages
- 1,124
- Office Version
- 365
- Platform
- Windows
Hi All,
I'm working on a code that checks to see if a file exists; then I would like it to open that file.
Right now, it tells me that it exists but how do I set it to open that file?
Please help me if you can I would really appreciate it!
Thank you!
pinaceous
I'm working on a code that checks to see if a file exists; then I would like it to open that file.
Right now, it tells me that it exists but how do I set it to open that file?
VBA Code:
Sub getfiles()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object, sf
Dim i As Integer, colFolders As New Collection, ws As Worksheet
'Dim folderPath As String
'Dim wb As Workbook
Dim fileName As String
Set ws = ActiveSheet
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\Users\Documents\New folder\")
colFolders.Add oFolder 'start with this folder
Do While colFolders.Count > 0 'process all folders
Set oFolder = colFolders(1) 'get a folder to process
colFolders.Remove 1 'remove item at index 1
'Do While fileName <> ""
For Each oFile In oFolder.Files
If oFile.DateLastModified > Now - 7 Then
ws.Cells(i + 1, 1) = oFolder.path
ws.Cells(i + 1, 2) = oFile.Name
'ws.Cells(i + 1, 3) = "RO"
ws.Cells(i + 1, 3) = oFile.DateLastModified
i = i + 1
End If
Next oFile
'add any subfolders to the collection for processing
For Each sf In oFolder.subFolders
colFolders.Add sf
Next sf
Loop
'Loop
fileName = Dir(folderPath & "BookOne.xlsx")
If strFileExists = "BookOne.xlsx" Then
MsgBox "The selected file doesn't exist"
Else
MsgBox "The selected file exists"
[B]'Workbooks.Open "BookOne.xlsx"[/B]
[B] 'THIS IS THE PART I NEED HELP WITH!![/B]
End If
End Sub
Please help me if you can I would really appreciate it!
Thank you!
pinaceous