I have some excel files in a share point folder. I would need the content from all the files to be collated to one single sheet using VBA.
I get the path as below and try to connect to the path where the files are available.The below code is not able to connect or read the file from the path.
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As File
strspURL = ThisWorkbook.Worksheets("Main").Cells(6, 7).Value
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strspURL)
Related
I am trying to get access the share point folder and files using VBA.
I have tried the same code to access the local folders and files it was working perfectly fine.
Here is my folder structure from share point. I need to access all the files inside the folder
Mainfolder
Folder 1
Folder 2
Folder 3
Folder 4
Option Explicit
Sub Somesub()
Call GetFiles("https://isharenew.xyz.com/main folder \")
End Sub
Sub GetFiles(ByVal path As String)
Dim spSite As String
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim folder As Object
Set folder = fso.GetFolder(path)
Dim subfolder As Object
Dim file As Object
For Each subfolder In folder.SubFolders
GetFiles (subfolder.path)
Next subfolder
For Each file In folder.Files
Range("L" & Rows.Count).End(xlUp).Offset(1, 0) = file.path
Next file
Set fso = Nothing
Set folder = Nothing
Set subfolder = Nothing
Set file = Nothing
End Sub
With my above code I am getting error Path Not Found
Please let me know where I am doing mistake.
I am trying to make a macro that opens all .xlsm files in a folder:
C:\Users\iborrego\Desktop\zfichasmacro\Fichas excel\
And copy some cells (from different worksheets).
Information from each file should be assigned only to one row as I will use the first row for titles (ID Nº; Date of visit etc …)
And one row for each file in the folder.
I would really appreciate if you could help me write the macro and tell me how it works as I am not an IT.
I did not understand the second part of your question, but here is a code which opens every xlsm in your given folder:
Sub Xlsmopener()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Users\iborrego\Desktop\zfichasmacro\Fichas excel")
i = 1
For Each objFile In objFolder.Files
If objFSO.GetExtensionName(objFile.Path) = "xlsm" Then
Workbooks.Open (objFile.Path)
End If
i = i + 1
Next objFile
End Sub
I have VBScript that is taking output from a Word file and generating a text file with that output. The current code shown below assumes that I want to create the file in my desktop.
The issue that I am having is that I plan to use wine on Linux to execute my VBScript. Is there anyway that i can modify this code to specify the Linux path to output this file?
fileName = "\out.txt"
strPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & fileName
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile(strPath)
I have a question regarding looping through a folder of two different kinds of files: xlsm and mdb (Access).
I have currently written a macro that would open 1 single xlsm file and 1 single mdb file before copying some data from the xlsm to mdb file and then saving the mdb file.
Now, I would like this process to repeat through a folder that has 50 xlsm files and 50 mdb files. They have the same names, so for example the loop should do this:
Open both xlsm and mdb files called "2001".
Perform copying and pasting etc from xlsm to mdb (I have written this part).
Save the mdb file.
Close both xlsm and mdb files called "2001".
Repeat steps 1-4 for "2002", "2003", etc in the folder.
I am really new to VBA so much help is appreciated! Looking forward to any guidance at all. Merry Christmas!
I just did today sample code for listing JPG files in folder, you can adopt and modify to do exactly what you like it to do, but would be very hard to give you exact code without being able to see your solution.
Public Sub listImages(folderPath As String)
'define variables
Dim fso As Object
Dim objFolder As Object
Dim objFolders As Object
Dim objF As Object
Dim objFile As Object
Dim objFiles As Object
Dim strFileName As String
Dim strFilePath As String
Dim myList As String
'set file system object
Set fso = CreateObject("Scripting.FileSystemObject")
'set folder object
Set objFolder = fso.GetFolder(folderPath)
'set files
Set objFiles = objFolder.files
Set objFolders = objFolder.subfolders
'list all images in folder
For Each objFile In objFiles
If Right(objFile.Name, 4) = ".jpg" Then
strFileName = objFile.Name
strFilePath = objFile.Path
myList = myList & strFileName & " - " & strFilePath & vbNewLine
End If
Next
'go through all subflders
For Each objF In objFolders
Call listImages(objF.Path)
Next
Debug.Print myList
Set objFolder = Nothing
Set objFile = Nothing
Set fso = Nothing
End Sub
Below is a very simple code for listing files in a specified folder. It works as expected.
However, when I provide one of the backup folders of this folder, it throws invalid path (backup folder path copied from win explorer window).
E.g.:
Set objFolder = objFSO.GetFolder("D:\Test")** 'works well
Set objFolder = objFSO.GetFolder("D:\Test (2015.2.12 3:12 PM)") 'not work. this is a previous/backup version of folder test created by Win7
Is there a way to list backup folder files with VBA in Excel?
Sub Example1()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("D:\Test")
'Set objFolder = objFSO.GetFolder("D:\Test (2015.2.12 3:12PM)") throws error
i = 1
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
'print file name
Cells(i + 1, 1) = objFile.Name
'print file path
Cells(i + 1, 2) = objFile.Path
i = i + 1
Next objFile
End Sub
How backup folders look like:
When I copy the path and paste it, some ? chars appear in the brackets:
\localhost\C$\Users\IBALLA1\Downloads (?Friday, ?April ?17, ?2015, ??9:05 AM)
You can't use colons in file names or folders names. The : in the time you have in a folder name can't be create and can't already be there. I don't know if that's a typo in your question or not though.