Ho costruito in precedenza un applicativo excel e access che lanciano ciascuno delle macro in sequenza.
Poi ho provato a fare un applicativo VB6 che le riprrnde e le esegue insieme.
Dopo la macro1 di excel ho inserito queste due righe perchè mi serviva salvare il file xlsm dove sono le tabelle e se non cancello e non lo salvo e rilancio l'applicativo mi da errore:
ActiveWorkbook.Save
Excel.ActiveWindow.Close
Ho notato anche che se da VB6 lanviavo la call excel che lancia titte le macro mi si bloccava quindi ho riportato tuttele macro di excel. Idem se tramite Vb6 lanciavo una macro che lancia tutte le macro Access
- Codice: Seleziona tutto
Private Sub Esci_Click()
Unload Me
End Sub
Private Sub Informazioni_Click()
Dim F As New frmAbout
F.Show
End Sub
Private Sub Istruzioni_Excel_Click()
Dim percorso As String
Dim S As Object
percorso = "File.xls"
Set S = CreateObject("Shell.Application")
S.ShellExecute (percorso)
End Sub
Private Sub Istruzioni_in_pdf_per_stampa_Click()
Dim percorso As String, file_xls As String, file_pdf As String, wbk As Workbook
percorso = "C:\"
file_xls = "File.xls"
file_pdf = "File.pdf"
Set wbk = Workbooks.Open(percorso & file_xls)
wbk.ExportAsFixedFormat Type:=xlTypePDF, _
FileName:=percorso & file_pdf, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
wbk.Close False
Set S = CreateObject("Shell.Application")
S.ShellExecute "C:\File.pdf"
End Sub
Private Sub Lancio_programma_Click()
'put this code inside the form load event of the Application
'change the file name and macro name to reflect your file and macro
'Open Excel and run the macro
If MsgBox("Attenzione. Lancio programma", vbYesNo) = vbYes Then
GoTo LancioprogrammaCompleto
If vbNo Then
GoTo Fine
LancioprogrammaCompleto:
Form1.Label1.Visible = True 'E' sul form1 in visible = false e contiene un messaggio "Programma in esecuzione, attendre..."
'create and object (Excel SpreadSheet)
Dim oXL As Object
Set oXL = CreateObject("Excel.Application")
' Open the workbook that contains the macro to run.
oXL.Workbooks.Open "C:\Macro.xlsm"
'as object opens invisible, make visible if needed, if not omit
'the line oXL.visible=true
oXL.Visible = True
'Macro Excel
oXL.Application.Run "'Macro.xlsm"'!Macro1"
ActiveWorkbook.Save
Excel.ActiveWindow.Close
oXL.Visible = False
oXL.DisplayAlerts = False
'Quit Microsoft Excel.
oXL.Quit
' Free the object from memory.
Set oXL = Nothing
Dim oXLb As Object
Set oXLb = CreateObject("Excel.Application")
' Open the workbook that contains the macro to run.
oXLb.Workbooks.Open "C:\Macro.xlsm"
oXLb.Visible = False
oXLb.Application.Run "'Macro.xlsm'!Macro2"
oXLb.DisplayAlerts = False
'Quit Microsoft Excel.
oXLb.Quit
' Free the object from memory.
Set oXLb = Nothing
'Macro Access
'http://www.xtremevbtalk.com/database-and-reporting/1942-running-access-macro-vb6.html
Dim objAccess As Access.Application
Set objAccess = New Access.Application
With objAccess
.OpenCurrentDatabase "C:\Database.accdb"
.DoCmd.RunMacro "1 - Macro Access"
.DoCmd.RunMacro "2 - Macro Access"
.DoCmd.RunMacro "3 - Macro Access"
.DoCmd.RunMacro "4 - Macro Access"
.DoCmd.RunMacro "5 - Macro Access"
.DoCmd.RunMacro "6 - Macro Access"
.DoCmd.RunMacro "7 - Macro Access"
.CloseCurrentDatabase
End With
objAccess.DoCmd.Quit
Set objAccess = Nothing
'Macro Excel
'create and object (Excel SpreadSheet)
Dim oXLs As Object
Set oXLs = CreateObject("Excel.Application")
' Open the workbook that contains the macro to run.
oXLs.Workbooks.Open "C:\Macro.xlsm"
'as object opens invisible, make visible if needed, if not omit
'the line oXL.visible=true
'
oXLs.Visible = False
' Run the macro.
oXLb.Application.Run "'Macro.xlsm'!Macro3"
oXLb.Application.Run "'Macro.xlsm'!Macro4"
oXLb.Application.Run "'Macro.xlsm'!Macro5"
oXLb.Application.Run "'Macro.xlsm'!Macro6"
oXLs.DisplayAlerts = False
' Quit Microsoft Excel.
oXLs.Quit
' Free the object from memory.
Set oXLs = Nothing
Form1.Label1.Visible = False
Form1.Label2.Visible = True 'E' sul form1 e contiene messaggio "Elaborazione terminata"
End If
Fine:
Exit Sub