Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Open only UserForm of an excel macro from batch file

I'm trying to open the UserForm1 of an excel macro through batch file. I'm able to open that but excel is also getting opened along with that. I want only UserForm1 to be opened not the excel. Below is my approach :

I have written a macros to open the UserForm1

Sub open_form()
   UserForm1.Show
End Sub

In batch File:

@echo off
cd "c:\Test\"
openFormTest.xlsm

By the above approach, When I'm running the batch file both UserForm1 and excel are getting open, but I want to open only UserForm1. Kindly help me out

like image 377
Samraan Avatar asked Dec 16 '13 04:12

Samraan


1 Answers

You need to show the UserForm in modeless mode and then hide the application.

try this

Sub open_form()
    Application.Visible = False
    UserForm1.Show vbModeless
End Sub

and either in a button you need to set it back to true or you can use the UserForm_QueryClose event

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Application.Visible = True
    ThisWorkbook.Close SaveChanges:=False
End Sub
like image 56
Siddharth Rout Avatar answered Sep 28 '22 20:09

Siddharth Rout