0
votes

I have multiple (sometimes 100+) xlsb files that the user is wanting to copy row 14 from Sheet8 from all files into one workbook/worksheet.

I am able to perform this function; however the results end up showing 0's for all of the calculated fields within the xlsb files

The xlsb files are macro run

In my code to open the file looks like this: 'This one works to open but doesn't run through Macro Set WorkBk = Workbooks.Open(FolderPath & FileName)

I updated the code with this; but then the next lines after it will not run, I believe because it is looking to "SET" and I am unsure how to perform this

 'This one opens and runs macro but then fails at Set SourceRange
 Workbooks.Open(FolderPath & FileName).RunAutoMacros Which:=xlAutoOpen

When I attempt to add .RunAutoMacros Which:=xlAutoOpen after the first code I get a Compile error: Expected: end of statement

 'This one works to open but doesn't run through Macro
 Set WorkBk = Workbooks.Open(FolderPath & FileName).RunAutoMacros Which:=xlAutoOpen

Here is the full code:

Sub MergeAllWorkbooks()
Dim SummarySheet As Worksheet
Dim FolderPath As String
Dim NRow As Long
Dim FileName As String
Dim WorkBk As Workbook
Dim SourceRange As Range
Dim DestRange As Range
Dim auto_open As String
Application.Calculation = xlCalculationAutomatic
' Create a new workbook and set a variable to the first sheet.
Set SummarySheet = Workbooks.Add(xlWBATWorksheet).Worksheets(1)

' Modify this folder path to point to the files you want to use.
FolderPath = "C:\Users\dredden2\Documents\SHAREPOINT ARCHIVING\PAGESETUP\TEST\"

' NRow keeps track of where to insert new rows in the destination workbook.
NRow = 2

' Call Dir the first time, pointing it to all Excel files in the folder path.
FileName = DIR(FolderPath & "*.xlsb")

' Loop until Dir returns an empty string.
Do While FileName <> ""
    ' Open a workbook in the folder

 'This one works to open but doesn't run through Macro
 Set WorkBk = Workbooks.Open(FolderPath & FileName)
    ' Set the cell in column A to be the file name.
    SummarySheet.Range("A" & NRow).Value = FileName

    ' Set the source range to be A9 through C9.
    ' Modify this range for your workbooks.
    ' It can span multiple rows.

    Set SourceRange = WorkBk.Sheets("Retrospective Results").Range("B14:BF14")

    ' Set the destination range to start at column B and
    ' be the same size as the source range.
    Set DestRange = SummarySheet.Range("B" & NRow)
    Set DestRange = DestRange.Resize(SourceRange.Rows.Count, _
       SourceRange.Columns.Count)

    ' Copy over the values from the source to the destination.
    DestRange.Value = SourceRange.Value

    ' Increase NRow so that we know where to copy data next.
    NRow = NRow + DestRange.Rows.Count

    ' Close the source workbook without saving changes.
    WorkBk.Close savechanges:=False

    ' Use Dir to get the next file name.
    FileName = DIR()
Loop

' Call AutoFit on the destination sheet so that all
' data is readable.
SummarySheet.Columns.AutoFit
 End Sub
1
If all the workbooks have the same macro name, will Call WorkBk.<macro name here> work for you? - FreeMan
I end up getting a run-time error '438': Object doesn't support this property or method. If the Macro inside the xlsb file is called Auto_Open() the code should be Call WorkBk.Auto_Open ? - David Redden
You may need to qualify which code module it's in. Call WorkBk.<module>.Auto_Open. - FreeMan
Application.Run _ "'" & FileName & "'!auto_open" - David Redden

1 Answers

0
votes

The final answer was:

      Application.Run _
    "'" & FileName & "'!auto_open"