Hello, I have a database(xlsb) to which a query connects and dumps the resulting table on another file(xlsm) and I'm trying to develop a piece fo code that, upon closing the database(xlsb) file it automatically updates the dependant file(xlsm). I've tried using that same file (xlsb) but it kep throwing errors, I then precceeded to add to the code a line that "saved as" the xlsb file and then connected the dependant file(xlsm) to this new file that is always created. This still doesnt work as when I open the dependant file(xlsm) the data is not updated. How can I make this code work? Following is the current code.
Rich (BB code):
Sub Workbook_BeforeClose(cancel As Boolean)
CarryOn = MsgBox("Atualizar planilhas dependentes? (Pode levar um minuto)", vbYesNo, "Atualizar planilhas dependentes")
If CarryOn = vbYes Then
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Application.EnableEvents = False
ThisWorkbook.SaveAs Filename:= _
"R:path\file.xlsb" _
, FileFormat:=50
Dim strFilename As String: strFilename = "R:path\file.xlsm"
Dim GPSMANUT As Workbook
Set GPSMANUT = Workbooks.Open(Filename:=strFilename)
GPSMANUT.RefreshAll
GPSMANUT.Connections("Consulta - Base de dados").Refresh
GPSMANUT.Connections("Consulta - Apoio$_FilterDatabase").Refresh
GPSMANUT.Save
GPSMANUT.Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
'Application.EnableEvents = True
ThisWorkbook.Save
Beep
MsgBox "Planilhas dependentes atualizadas!"
End If
End Sub
Private Sub Workbook_Open()
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub