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!!!
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!!!