Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have this code (Thank you Bob Phillips):
Code:
Sub LoopFolders() Dim oFSO Dim Folder As Object Dim Files As Object Dim file As Object Set oFSO = CreateObject("Scripting.FileSystemObject") Set Folder = oFSO.GetFolder("c:\MyTest") For Each file In Folder.Files If file.Type Like "*Microsoft Excel*" Then Workbooks.Open Filename:=file.Path '<<<<< run macro here on Activeworkbook Activeworkbook.Close SaveChanges:=False End If Next file Set oFSO = Nothing End Sub Code:
Sub OpenWorkbooks() Dim oFSO Dim Folder As Object Dim Files As Object Dim file As Object 'Modified macro from Bob Phillips 'Application.ScreenUpdating = False 'temporarily disabled ThisWorkbook.Worksheets("INSTRUCTIONS").Activate 'select cells from "INSTRUCTIONS" workbook Cells.Copy 'copy all cells Set oFSO = CreateObject("Scripting.FileSystemObject") Set Folder = oFSO.GetFolder("U:\VBA\Test Folder") 'For Each file In Folder.Files If file.Type Like "*Microsoft Excel*" Then 'ERROR IS AT THIS LINE Workbooks.Open Filename:=file.Path '<<<<< run macro here on Activeworkbook Worksheets("INSTRUCTIONS").Activate 'select worksheet "INSTRUCTIONS" ActiveSheet.Paste 'paste cells from original worksheet ActiveWorkbook.Close SaveChanges:=True End If 'Next file Set oFSO = Nothing End Sub "Object varaible or With block variable not set" What is failing? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Need help with Error 'object variable or with block variable not set' | Excel Programming | |||
Run-Time error '91': Object variable of With block variable not set | Excel Programming | |||
Run-time error '91': "Object variable or With block variable not set | Excel Programming | |||
Cells.Find error Object variable or With block variable not set | Excel Programming | |||
Pivot Table - Object variable or with block variable not set? | Excel Programming |