Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-09-2017, 05:46 AM
mihnea96 mihnea96 is offline Searching through folders/ subfolders and rename files if certain condition is met Windows 7 32bit Searching through folders/ subfolders and rename files if certain condition is met Office 2010 32bit
Novice
Searching through folders/ subfolders and rename files if certain condition is met
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default Searching through folders/ subfolders and rename files if certain condition is met

Hi! I'm trying to rename some files/documents in a folder and its sub-folders (located in a online sharepoint), beacuse, when copying them, I get an error saying that the file name is too long. I'be been trying to use the code bellow, but it doesn't work. Could you help me, please?



Code:
Sub command_button1()

Const FILEPATH As String = "HYPERLINK"
Const NEWPATH As String = "HYPERLINK"


Dim strfile As String
Dim freplace As String
Dim flocation As String
Dim fsuffix As String
Dim propfname As String
Dim fls, f

With flocaion
.SearchSubFolders = True
.LookIn = "C:\Users\mihneion\Desktop\TEST RENAMING FILES"
Set fls = GetFiles(FILEPATH)
For Each f In fls
    Debug.Print f
    strfile = Dir(f)
      If Len(strfile) > 199 Then strfile = Left(strfile, 199)
        propfname = FILEPATH & strfile
        FileExistsbol = FileExists(propfname)
          If FileExistsbol Then
          Kill propfname
          End If
        Name FILEPATH & strfile As propfname
        'fso.CopyFile(FILEPATH & propfname, NEWPATH & propfname, True)
      End If
Next f
End With
End Sub

Function GetFiles(path As String, Optional pattern As String = "") As Collection
Dim rv As New Collection, f
If Right(path, 1) <> "\" Then path = path & "\"
f = Dir(path & pattern)
Do While Len(f) > 0
    rv.Add path & f
    f = Dir() 'no parameter
Loop
Set GetFiles = rv
End Function
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to change/convert/delete txt files in folder+subfolders NoS Word VBA 4 03-03-2016 12:10 PM
Can a macro rename Excel files based on a cellname? chrisd2000 Excel Programming 1 06-23-2014 06:50 PM
Rename Files gsrikanth Excel Programming 3 05-14-2012 03:03 AM
Can't create subfolders in shared Contact folders shellyrc7 Outlook 0 03-30-2012 08:18 PM
Searching Outlook folders not working cltaylor Outlook 0 08-31-2009 10:28 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft