Workbook openen op de achtergrond, opslaan en weer sluiten

Status
Niet open voor verdere reacties.

CFB

Nieuwe gebruiker
Lid geworden
10 feb 2019
Berichten
4
Hi all,

Elke maand moet ik meerdere excel bestanden opslaan van format xlsb naar xlsm. Ik wil dit graag automatiseren doormiddel van een Macro. Ik wil dat de files op de achtergrond worden geopend (zodat de gebruiker dit niet ziet), de files worden opgeslagen en daarna weer worden gesloten. Zonder dat de gebuiker moet klikken op alle allerts.

Ik heb nu de onderstaande code geschreven, maar met deze code wordt het bestand op de "voorgrond geopend". Je ziet dat het bestand wordt geopend moet eerst op alle updates en messages drukken, daara wordt het bestand opgeslagen en gesloten. Mijn bedoeling is dus juist dat je niet ziet dat de file wordt geopend en dat je niet op alle messages moet drukken. Kan iemand mij helpen op de onderstaande code aan te passen?

Private Sub CommandButton1_Click()
MsgBox "Copy Start"

Dim path As String
Dim filename As String

Application.DisplayAlerts = False
Workbooks.Open ("W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\BG_Hub_Bulgaria\DC_Data_2019_ACT.xlsb")
ActiveWorkbook.SaveAs filename:= _
"W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\BG_Hub_Bulgaria\DC_Data_2019_ACT.xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Workbooks.Close
Application.DisplayAlerts = True



MsgBox "Done with the copy!"


End Sub
 
Gebruik ook Application.ScreenUpdating = False
 
Hi,

Bedankt voor de tip. Ik heb de code toegevoegd op verschillende plaatsen om het uit te testen je ziet nu niet meer de inhoud van de excel sheet, dit is al een stap vooruit.
Als ik de macro nu run wordt het excel bestand geopend, moet ik klikken op enable macro's en moet ik nog steeds klikken op update / niet update de file. De excel file wordt daarna automatisch opgeslagen en gesloten. Waar ik nu nog naar opzoek ben is dat je ook niet meer hoeft te klikken op enable macro's, update / niet update en dat je de andere excel file helemaal niet ziet.

Mijn code ziet er nu als volgt uit:
Private Sub CommandButton1_Click()
MsgBox "Copy Start"

Dim path As String
Dim filename As String

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Open ("W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\BG_Hub_Bulgaria\DC_Data_2019_ACT.xlsb")
ActiveWorkbook.SaveAs filename:= _
"W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\BG_Hub_Bulgaria\DC_Data_2019_ACT.xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Open ("W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\DE_3PL_MGL\DC_Data_2019_ACT.xlsb")
ActiveWorkbook.SaveAs filename:= _
"W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\DE_3PL_MGL\DC_Data_2019_ACT.xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True


MsgBox "Done with the copy!"


End Sub
 
Laatst bewerkt:
Hi,

Bedankt voor de tip. Ik heb de code toegevoegd op verschillende plaatsen om het uit te testen je ziet nu niet meer de inhoud van de excel sheet, dit is al een stap vooruit.
Als ik de macro nu run wordt het excel bestand geopend, dan moet ik nog steeds klikken op enable macro's en update / niet update. De excel file wordt daarna automatisch opgeslagen en gesloten. Waar ik nu nog naar opzoek ben is dat je ook niet meer hoeft te klikken op enable macro's, update / niet update en dat je de andere excel file helemaal niet ziet.

Mijn code ziet er nu als volgt uit:
Private Sub CommandButton1_Click()
MsgBox "Copy Start"

Dim path As String
Dim filename As String

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Open ("W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\BG_Hub_Bulgaria\DC_Data_2019_ACT.xlsb")
ActiveWorkbook.SaveAs filename:= _
"W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\BG_Hub_Bulgaria\DC_Data_2019_ACT.xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Open ("W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\DE_3PL_MGL\DC_Data_2019_ACT.xlsb")
ActiveWorkbook.SaveAs filename:= _
"W:\International\FINANCE & PM\Supply Chain\21 EMEA GOPS\03 Reporting\AMS Centralized Functions\L1 Report\Volumes\OB Volumes\DE_3PL_MGL\DC_Data_2019_ACT.xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True


MsgBox "Done with the copy!"


End Sub
 
Dat van die update zal een instelling van een datalink in het document zijn.
Als het een datalink is kan je dat in het document zelf aanpassen.

Het direct gebruiken van macro's kan je inschakelen in het Vertrouwenscentrum.
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan