1 year ago

#360398

test-img

OriginalStealth

VBA Error No Such Interface Supported (I am using MS Access app to manipulate excel files/data

I am using an MS Access App to manipulate files. The gyst is I want to loop thru all folders and subfolders, open each workbook and if the mastersheet tab exists, delete it. If not, create it. Works fine for the first folder but errors on the file. Also when I try to open the price file that had the tab added to it in explorer, both the price file and master file open at once. Any help is greatly appreciated!!! Thanks in advance!

Private Sub ProcessFilesBtn_Click()
'Windows object variables
Dim fso As Object
Dim folder As Object
Dim subfolders As Object
Dim CurrFile As Object
Dim MyFile As String

'Folder and subfolder location variables
Dim DivisionFolder As String
Dim sFileName As String

'Excel workbook variables
Dim PriceGrid As Excel.Workbook
Dim xlapp As Excel.Application
Dim xlSheet As Excel.Worksheet
Dim xlPath As String

Dim SheetName As String
Dim TotalSheets As Integer
Dim MasterWorkbook As Workbook
Dim msheet As Worksheet


''Set Object Variables
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("C:\Users\name\Desktop\Pricing Tool\Price Grids\")
Set subfolders = folder.subfolders
SheetName = "MasterSheet"

    For Each subfolders In subfolders
   
        Set CurrFile = subfolders.Files
       
        For Each CurrFile In CurrFile
            Debug.Print subfolders.Path & "\" & CurrFile.Name
            Debug.Print subfolders.Name
            Debug.Print CurrFile.Name
            Set PriceGrid = Workbooks.Open(subfolders.Path & "\" & CurrFile.Name)
            
            Set xlapp = CreateObject("Excel.Application")
            Set MasterWorkbook = xlapp.Workbooks.Open("C:\Users\name\Desktop\Pricing Tool\MasterSheet")
            
            'Step 1 - If the MasterSheet tab exists on the PriceGrid tab, delete and recreate it.  This is for reloads when data is updated -add in Loop
            For Each xlSheet In PriceGrid.Worksheets
                Debug.Print xlSheet.Name
                If SheetName = xlSheet.Name Then
                    xlSheet.Delete
                End If
            Next xlSheet

            'Copies the master worksheet to the PriceGrid workbook -Add to Loop
            For Each msheet In MasterWorkbook.Sheets
                msheet.Copy Before:=PriceGrid.Sheets(1)
            Next
                
            'Save changes and close workbook
             PriceGrid.Save
             PriceGrid.Close
             MasterWorkbook.Close      
        Next      
    Next    
    Set fso = Nothing
    Set folder = Nothing
    Set subfolders = Nothing

I tried files in the same folder, files in different folders, creating new files. Tried some of the answers from the other articles. No success.

excel

vba

ms-access

excel-2016

file-copying

0 Answers

Your Answer

Accepted video resources