Hi all! I found this code online a while back and have been using it and it works great, but now I'd like to remove the user input from the process and instead derive the folder path from variables that were assigned earlier in the macro...
The previous version...
So basically I just want to replace the folder picker with "CYPVS", which is a variable that I have assigned the file path too... and I can't seem to get it to work. Incase it's not clear from the code, the desired result is a list of all the file names (not paths) in the folder, starting in cell B2 and going down. Also, if anyone knows how to only list the .pdf files, that would be helpful!
In this snippet the filename:=xDirect2015PVS would be replaced with filename:=CYPVS & PDFRef is the variable looping through the file names.
Thanks in advance!
Joe
The previous version...
Code:
Sub GetFileNames()
Dim LastRow As Long
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
Range("A:B").ClearContents
InitialFoldr$ = "H:\"
With Application.FileDialog(msoFileDialogFolderPicker) '//I would like to change this to something like... (FldrRoot & "\" & FldrLvl1 & "\" & FldrLvl2 & "\" & Year(Date) & " PVS")\\
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
Range("B1").Activate
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
So basically I just want to replace the folder picker with "CYPVS", which is a variable that I have assigned the file path too... and I can't seem to get it to work. Incase it's not clear from the code, the desired result is a list of all the file names (not paths) in the folder, starting in cell B2 and going down. Also, if anyone knows how to only list the .pdf files, that would be helpful!
Code:
Set IPDF = Sheets(Year(Date) - 1 & " PVS").OLEObjects.Add(Filename:=xDirect2015PVS$ & PDFRef, Link:=False, DisplayAsIcon:=False) '//Insert PDF, see Explanations sheet\\
With IPDF
.Top = Sheets(Year(Date) - 1 & " PVS").Range("A1").Top '//Set the top to be cell A1\\
.Left = Sheets(Year(Date) - 1 & " PVS").Range("A1").Left '//Set the left to be cell A1\\
End With
In this snippet the filename:=xDirect2015PVS would be replaced with filename:=CYPVS & PDFRef is the variable looping through the file names.
Thanks in advance!
Joe