Hi,
In the code below, what is the purpose of the object objFSO?
Do I need it if all I require is the path selected by the user so I can save the file. (I got this code somewhere and I've just used it as is, but in stepping through the code I see that it really just assigns the save string of strFolderPath to objFolder? What is the reason for this??
IOW: Can I scrap the entire Set objFSO in the red square and in the code above the red line just say: Filename:=strFolderPath & "\" & FName?
What is the purpose of objFSO?
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
What is the purpose of objFSO?
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78530
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: What is the purpose of objFSO?
I can't tell whether objFile is used further down, but in the part of the code that you posted, there is no need to use objFSO and objFolder. You could indeed use
NewBook.SaveAs FileName:=strFolderPath & "\" & FName
NewBook.SaveAs FileName:=strFolderPath & "\" & FName
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: What is the purpose of objFSO?
No, its not used further down. Just for the saving path.HansV wrote:I can't tell whether objFile is used further down, but in the part of the code that you posted, there is no need to use objFSO and objFolder. You could indeed use
NewBook.SaveAs FileName:=strFolderPath & "\" & FName
Could you tell me what is the CreatObject("Scripting.FileSystemObject")? What is its purpose in the original code that I got...as attached below?
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78530
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: What is the purpose of objFSO?
FileSystemObject is an object from VBScript that presents an interface to the file system (drives, folders and files). It also lets you manipulate text files.
Since it is not included in VBA, you need to create an instance of FileSystemObject to work with it.
In the code from your text file, the line
creates a folder object that refers to the folder whose path is strFolderPath.
objFolder.Files is the collection of all files in this folder.
The code loops through these files and lists their names in a worksheet.
Since it is not included in VBA, you need to create an instance of FileSystemObject to work with it.
In the code from your text file, the line
Code: Select all
Set objFolder = objFSO.GetFolder(strFolderPath & "\")
objFolder.Files is the collection of all files in this folder.
The code loops through these files and lists their names in a worksheet.
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: What is the purpose of objFSO?
Ah, so properties of the Folder object are being used in the attached file code, hence the need for an object definition.
In my code, I just need a string for the path to the save folder. I do not need properties of the folder object, so hence no need to have it in the code. (Phew! - got it!)
TX
In my code, I just need a string for the path to the save folder. I do not need properties of the folder object, so hence no need to have it in the code. (Phew! - got it!)
TX
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.