Getfolder Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us run time error 91 vba Learn more about Stack Overflow the company Business Learn more about hiring developers
Run Time Error 91 Object Variable Or With Block Variable Not Set
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack run time error 91 excel vba Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up VBS can't find directory - 'Path Not Found'
How To Fix Runtime Error 91 Object Variable Not Set
up vote 2 down vote favorite I have a script that obtains information about the current folders and subfolders within a specific directory. It works great, but I have stumbled across a strange issue: dim FSO, objFolder, datafolder, foldername, objSubfolder, totalSize dim objSubfolder2, objFolder2, mSize, size, today, dateLastMod foldername = "D:\folder\subfolder" set FSO = CreateObject("Scripting.FileSystemObject") set objFolder = FSO.GetFolder(foldername) set colSubfolders = objFolder.Subfolders today = Now ShowFolderDetails run-time error '91' in excel macro objFolder Function ShowFolderDetails(oF) datafolder = oF.Size/1073741824 wscript.echo oF.Name & " :Size= " & datafolder & " GB" wscript.echo oF.Name & " #Files= " & oF.Files.Count wscript.echo oF.Name & " #Folders= " & oF.Subfolders.count wscript.echo oF.Name & " Date Last Modified= " & oF.DateLastModified totalSize = totalSize + datafolder end Function And there is more to follow, but my issue is I get a path not found when I call that function. The folder is not located on the C:\ drive - which shouldn't be an issue. I have done this same script but changed foldername = D:\folder\differentsubfolder which works perfectly. But when I change it back to the other folder, it gives me a path not found error. I also tried putting everything below set FSO = CreatObject("Scripting.FileSytemObject") within an IF statement: IF FSO.FolderExists(foldername) Then .... This does enter in that IF statement, which makes me believe the VBS sees it, but I still get that error at line 17 (datafolder = oF.Size/1073741824). I have tried putting in the full folder path where the variable foldername is located (surrounded in quotes). I tried running my vbs pointed to other directories and it runs 100%. Its just that specific folder
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and
Runtime Error 91 Windows 7
reference Dev centers Retired content Samples We’re sorry. The content you requested
Object Variable Or With Block Variable Not Set Vba
has been removed. You’ll be auto redirected in 1 second. Reference Trappable Errors Core Visual Basic Language Errors object variable or with block variable not set vb6 error Core Visual Basic Language Errors 91 Object variable or With block variable not set 91 Object variable or With block variable not set 91 Object variable or With block variable http://stackoverflow.com/questions/11019003/vbs-cant-find-directory-path-not-found not set 3 Return without GoSub 5 Invalid procedure call or argument 6 Overflow 7 Out of memory 9 Subscript out of range 10 This array is fixed or temporarily locked 11 Division by zero 13 Type mismatch 14 Out of string space 16 Expression too complex 17 Can't perform requested operation 18 User interrupt occurred 20 Resume without error 28 https://msdn.microsoft.com/en-us/library/aa264506(v=vs.60).aspx Out of stack space 35 Sub, Function, or Property not defined 47 Too many DLL application clients 48 Error in loading DLL 49 Bad DLL calling convention 51 Internal error 52 Bad file name or number 53 Can't find specified file 54 Bad file mode 55 File already open 57 Device I\O error 58 File already exists 59 Bad record length 61 Disk full 62 Input past end of file 63 Bad record number 67 Too many files 68 Device unavailable 70 Permission denied 71 Disk not ready 74 Can't rename with different drive 75 Path\File access error 76 Path not found 91 Object variable or With block variable not set 92 For loop not initialized 93 Invalid pattern string 94 Invalid use of Null 96 Can't sink this object's events because it's already firing events... 97 Can't call Friend procedure on an object that isn't an instance of... 98 A property or method call cannot include a reference to a private ... 321 Invalid file format 322 Can't create necessary temporary file 400 Form already displayed; can't show moda
for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack http://codereview.stackexchange.com/questions/86441/excel-vba-get-folder-names Overflow the company Business Learn more about hiring developers or posting ads with us Code Review Questions Tags Users Badges Unanswered Ask Question _ Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Excel time error VBA - Get Folder Names up vote 4 down vote favorite 1 I need to get folder names with the path for which I need to search the directory in a server with about 6000 folders. I have the following snippet of code to run through the folder and get the folder names with path. It works fine in a local directory but when I run the same code on a time error 91 server directory it fails after about printing 86 folder names. The code works absolutely fine but stops working when run on a server directory with about 6000 folders. Excel freezes up and seems like it hangs. Private Sub PrintFolders() Dim objFSO As Object Dim objFolder As Object Dim objSubFolder As Object Dim i As Integer Application.StatusBar = "" 'Create an instance of the FileSystemObject Set objFSO = CreateObject("Scripting.FileSystemObject") 'Get the folder object Set objFolder = objFSO.GetFolder("C:\Temp") i = 1 'loops through each folder in the directory and prints their names and path On Error GoTo handleCancel Application.EnableCancelKey = xlErrorHandler MsgBox "This may take a long time: press ESC to cancel" For Each objSubFolder In objFolder.subfolders Application.StatusBar = objSubFolder.Path & " " & objSubFolder.Name 'print folder name Cells(i + 1, 1) = objSubFolder.Name 'print folder path Cells(i + 1, 2) = objSubFolder.Path i = i + 1 Next objSubFolder handleCancel: If Err = 18 Then MsgBox "You cancelled" End If End Sub vba excel share|improve this question edited Apr 9 '15 at 22:23 asked Apr 9 '15 at 19:51 Anurag Singh 8217 1 I'm on the fence here. The code works... but fails because I presume the folder names get too long. Do they? It's impossible to tell just by looking at th