![]() |
Object varaible or With block variable not set?
I have this code (Thank you Bob Phillips):
Code:
Sub LoopFolders() Code:
Sub OpenWorkbooks() "Object varaible or With block variable not set" What is failing? |
Object varaible or With block variable not set?
From a quick look at your code, it seems you have commented out the line
'For Each file In Folder.Files Since it is this line of code that sets the 'file' variable to a specific File object, you will get an "object not set" error because the variable 'file' hasn't been set to any File in particular. Somehow, you need to set 'file' to a File object. Perhaps Set file = oFSO.GetFile("C:\Whatever\Test.xls") -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting www.cpearson.com (email on the web site) "Rick S." wrote in message ... I have this code (Thank you Bob Phillips): Code:
Sub LoopFolders() Modified as so: Code:
Sub OpenWorkbooks() Neither one will work and I get the follwoing error: "Object varaible or With block variable not set" What is failing? |
Object varaible or With block variable not set?
I believe I have narrowed this down to the following line of code:
If file.Type Like "*Microsoft Excel*" Then I think that excel is not recognizing my files as "Microsoft Excel"!? "Rick S." wrote: Seems to be another underlying issue. The code stops running after "Cells.Copy 'copy all cells" I added two "MsgBox" to show the true or false status of the "cells.copy" event and for after a new file is opened. The first message box prompts with true and then the code exits, at least it appears to exit. Code:
Sub OpenWorkbooks() I should see a second message box with either True or false and the text "2nd Test" while the new file is open (or thru all excel files in the path). Is there Network drive name issues with Excel 2007!? Do I have to type the actual network name? Example: "Server\MyNetwork\VBA\Test Folder" P.S. I forgot to mention I am using Excel 2007 (hate it so far). :shrug: |
Object varaible or With block variable not set?
Moving forward...
So far I found that the code: "If file.Type Like "*Microsoft Excel*" Then" is not functioning as planned and now my new code functions and recognizes the files in the folder. : "For Each file In Folder.Files sFileName = file If Right(sFileName, 3) = "xls" Then" Butt, now I can't seem to pass the password to the file that will be opened without user intervention, I am prompted with a dialog box to enter a password, select Read Only or select Cancel. "Workbooks.Open FileName:=file.Path, Password:=€śxxxx€ť" The above simply opens the file with the dialog box for a password. I have also tried "Workbooks.Open FileName:=file.Path, WriteResPassword:=€śxxxx€ť" which fails to recognize the password. It appears I only need to resolve the password issue, I have thousands of files to iterate thru and retyping the password would be something I would whine about for generations to come. Any help other than my own would be aprreciated LOL |
Object varaible or With block variable not set?
Password issue resolved, thanks to Gary Kermidas.
Quote:
"Rick S." wrote: Moving forward... So far I found that the code: "If file.Type Like "*Microsoft Excel*" Then" is not functioning as planned and now my new code functions and recognizes the files in the folder. : "For Each file In Folder.Files sFileName = file If Right(sFileName, 3) = "xls" Then" Butt, now I can't seem to pass the password to the file that will be opened without user intervention, I am prompted with a dialog box to enter a password, select Read Only or select Cancel. "Workbooks.Open FileName:=file.Path, Password:=€śxxxx€ť" The above simply opens the file with the dialog box for a password. I have also tried "Workbooks.Open FileName:=file.Path, WriteResPassword:=€śxxxx€ť" which fails to recognize the password. It appears I only need to resolve the password issue, I have thousands of files to iterate thru and retyping the password would be something I would whine about for generations to come. Any help other than my own would be aprreciated LOL |
All times are GMT +1. The time now is 12:39 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com