LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Object varaible or With block variable not set?

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
Modified as so:

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
Neither one will work and I get the follwoing error:
"Object varaible or With block variable not set"

What is failing?
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with Error 'object variable or with block variable not set' Francois via OfficeKB.com Excel Programming 5 April 30th 07 03:05 PM
Run-Time error '91': Object variable of With block variable not set jammin1911 Excel Programming 3 June 6th 06 06:36 PM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM


All times are GMT +1. The time now is 08:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"