I hope somebody wouldn’t mind just helping me a bit here as I am stuck. I have some excel documents in a folder all named as a unique 5 digit number which I have created. Each of these excel documents has a button on them which runs a macro “TransferToWIPAndSort” . This transfers data from the open file to a file called WIP.
I am building some code which I hope will open each of these files in the folder, run the embedded code and then close the file. I have the code working until I reach the point of running the embedded code which I can’t get to work.
Any help is appreciated
I have tried the following lines of code
Main code
I am building some code which I hope will open each of these files in the folder, run the embedded code and then close the file. I have the code working until I reach the point of running the embedded code which I can’t get to work.
Any help is appreciated
I have tried the following lines of code
VBA Code:
'Application.Run "myfileTransferToWIPAndSort"
Application.Run "'myfile.xlsm'!TransferToWIPAndSort"
'Call TransferToWIPAndSort
Main code
VBA Code:
Sub AllFiles()
Dim i As Long
Dim Ws As Worksheet
Dim Wkbk As Workbook
'Dim myfile As Workbook
Dim sht As Worksheet
myDir = "W:\Sub-Contract\Test"
'myDir = "W:\1works managers files\Cost sheets\Cost sheets test"
'myDir = "W:\1works managers files\Cost sheets"
myfile = Dir(myDir & Application.PathSeparator & "*.xlsm", vbDirectory)
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
Set Ws = Worksheets("Sheet1")
Ws.Range("B3:E500").ClearContents 'Clear Data in Column B3 to E500
i = 3 ' this is starting a Row 1 then offsetting to row 3
Do While myfile <> ""
If myfile <> "WIP.XLSX" Then Workbooks.Open filename:=myDir & "\" & myfile, UpdateLinks:=False
Ws.Cells(i, 2) = myfile ' this is offsetting from column A to column B
Set Wkbk = Workbooks.Open(myDir & "\" & myfile, False) ' the false on the end prevents update links and opens read only
Sheets("Cost Sheet").Select ' select the sheet cost sheet on the opened excel file then run the code in this workbook
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'Application.Run "myfileTransferToWIPAndSort"
Application.Run "'myfile.xlsm'!TransferToWIPAndSort"
'Call TransferToWIPAndSort
'Call a subroutine here to run on the just-opened workbook
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Wkbk.Close False
myfile = Dir
i = i + 1
Loop
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub