Opening and closing multiple files

lakke2120

New Member
Joined
Aug 21, 2014
Messages
32
Hello,
I have a code that works great. The code opens all the files in a folder and compiles it to a table on my master spreadsheet. The problem I have is that when the program opens the files I have to click on update for each file because they all have link to a database. It's a lot of files and I don't want to be doing that each time each one opens. I need for those files to be linked to the database only when they are created but not when I save them. Is there a code to save the files without the link to the database? Or is there a code I can add to allow me to open those files with the update prompt for each one?

Here is the code I have to save the files (its save to two locations)

rivate Sub Workbook_BeforeClose(Cancel As Boolean)

If MsgBox("Would you like to back up file?", vbYesNo) = vbYes Then _

Dim newFile As String, fName As String
' Don't use "/" in date, invalid syntax
fName = Sheets("SAP 1 PRINT ONLY").Range("A1").Value
'Change the date format to whatever you'd like, but make sure it's in quotes
newFile = fName & " " & Format$(Date, "mmmm-yyyy")
' Change directory to suit your PC, including USER NAME
ChDir _
"S:\Active Individual Programs\Manager folder\New Programs\"
ActiveWorkbook.SaveAs Filename:=newFile
ActiveWorkbook.SaveAs "S:\Active Individual Programs\All Individual SAP Programs\Adrian Garcia\2015\Data\" + ActiveWorkbook.Name
End If
End Sub

Here is the code I have to open the files

Sub CombineData()
Dim myDir As String, filename As String
Dim lrdata As Long
Dim masterws As Worksheet

Application.ScreenUpdating = False
Set masterws = ThisWorkbook.Sheets("Data")
myDir = "S:\Active Individual Programs\Manager folder\New Programs\" '<- Change here (Folder path)
filename = Dir(myDir & "\*.xls*")
Do While filename <> ""
With Workbooks.Open(myDir & "\" & filename)
With Sheets("Report")
lrdata = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A2:AA187" & lrdata).Copy
masterws.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
End With
filename = Dir
End With
Loop

End Sub


thank you very much!!!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Possibly adding
Application.DisplayAlerts = False ' Gets rid of all the updates pop ups
Do While filename <> ""
With Workbooks.Open(myDir & "\" & filename)
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources ' Updates all the links in the workbook
 
Upvote 0
Thank you so much DebugGalpin, for your assistance. I probably put your code in the wrong place. Can you tell me where I would put it in my code.
thanks
 
Upvote 0
SOLVED

added updatelinks:=0 and it worked perfectly

With Workbooks.Open(myDir & "\" & filename, UpdateLinks:=0)


thanks
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top