@Robert: I tried to adapt your code with a relative path and created a batch file to run VBS.
VBS starts and closes, but doesn't run the macro ... Any idea on where the problem could be?
Option Explicit On Error Resume Next ExcelMacroExample Sub ExcelMacroExample() Dim xlApp Dim xlBook Set xlApp = CreateObject("Excel.Application") Set objFSO = CreateObject("Scripting.FileSystemObject") strFilePath = objFSO.GetAbsolutePathName(".") Set xlBook = xlApp.Workbooks.Open(strFilePath, "Excels\CLIENTES.xlsb") , 0, True) xlApp.Run "open_form" Set xlBook = Nothing Set xlApp = Nothing End Sub
I deleted "Application.Quit" because my macro invokes a custom form, taking care of this.
Greetings
EDIT
I really worked it out, just in case someone wants to run a custom form βlikeβ a standalone application:
Problems I encountered:
1 - I did not want to use the Workbook_Open event, since excel is read-only blocked. 2 - The party team is limited by the fact that (as far as I know) it cannot call a macro.
First I wrote a macro to run my custom form, hiding the application:
Sub open_form() Application.Visible = False frmAddClient.Show vbModeless End Sub
Then I created vbs to run this macro (doing this with a relative path was complicated):
dim fso dim curDir dim WinScriptHost set fso = CreateObject("Scripting.FileSystemObject") curDir = fso.GetAbsolutePathName(".") set fso = nothing Set xlObj = CreateObject("Excel.application") xlObj.Workbooks.Open curDir & "\Excels\CLIENTES.xlsb" xlObj.Run "open_form"
And I finally made a batch file to run VBS ...
@echo off pushd %~dp0 cscript Add_Client.vbs
Note that in my Userform_QueryClose :
I also included "Set back to visible"
Private Sub cmdClose_Click() Unload Me End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) ThisWorkbook.Close SaveChanges:=True Application.Visible = True Application.Quit End Sub
Anyway, thanks for your help and I hope this helps if someone needs it