Is it possible to run a macro on web browser? I can open an excel in a browser but i am not sure if macro can run with it. And also, how am I going to enable it automatically within a browser?
If I am correct in assuming that you're asking if a vba macro can be run automatically after opening it from a link on a webpage rendered by a browser, the best way to do that is to set code to run automatically whenever the workbook linked in the webpage is opened.
To have a macro run when a workbook is opened double click the "ThisWorkbook" object in the vba project explorer of the workbook that has your code and add these lines of code
Private Sub Workbook_Open()
Call Module1.hello 'Change this line to start your code
End Sub
This automatically executes the sub "hello" in Module1 of the workbook.
Note that the user has to have Macros Enabled in their Trust Center Settings for anything to run.
Also note that depending on their browser and where the actual link points to the workbook file might have to be downloaded first and then opened from the download location for the macro to run.
Related
I need this macro to run when the .xlsm workbook is opened. It only runs if I manually run the macro, it does not start when the workbook is opened. FYI, I've checked/verified macro security (this is not signed yet).
Any ideas what I'm doing wrong?
Sub Workbook_Open()
MsgBox "Hello World!"
End Sub
Your code needs to be located in the ThisWorkbook module.
Open the VBA Editor (Alt+F11)
Open the Project Explorer (Ctrl+R)
In the Project Explorer pane, double click ThisWorkbook. (If you have multiple workbooks open, make sure you choose the ThisWorkbook under the correct project.)
In the code editor pane, click the drop-down that says General.
This will bring you to a new (or existing) Workbook_Open procedure:
Private Sub Workbook_Open()
End Sub
That's where your code should be placed.
Note that clicking the other drop-down at the top-right of the Code Editor pane, will list the other Workbook-level procedures you can add.
More Information:
Chip Pearson : Code Module And Code Names
I am making an app using Excel, with all user interaction happening in userforms. I would like my app to run in a separate instance of excel than any other file already opened, or any file opened manualy by the user while my app runs. I found the folowing link to be relevant and interesting but I am not sure how to implement this in my application: Answers.microsoft.com Can I create an instance of Excel that can only be accessed by my VBA project?
Here is how I would like to implement it:
I use two files: StartFile.xlsb, SystemFile.xlsb
The user opens StartFile normaly by clicking on the file
Sheet1 of StartFile displays a warning if macros are not enabled.
Once macros are enabled, StartFile checks excel version etc...
If all is good StartFile then opens SystemFile in a new instance of excel, and closes itself
SystemFile opens and somehow makes its excel instance private (Using "Application.IgnoreRemoteRequests = True" ?)
Clarification: The user will not be able to interact with the private excel instance application at all. Its .visible setting will remain false. It is used to display userforms, so to the user this will look like a standalone app
Sidenote: How do I make sure my new instance of excel has macros enabled no matter the macro security settings? (the user has already enabled macros once) (I have not noticed this happening so far, could it?)
Is it something like this you are looking for?
You cannot change the macro security settings as that would undermine the whole purpose of having these settings. Alternative, you can properly search for a VBA module to changing the Windows registry for this.
Furthermore, be careful if you use IgnoreRemoteRequeststhen you have to reset it again everytime.
** Edited ** Hide the SystemFile workbook and just show the userform? And then close the SystemFile workbook when the userform is closed.
Private Sub Workbook_Open()
Application.Visible = False
UserForm1.Show
End Sub
'UserForm module
Private Sub CommandButton1_Click()
Unload UserForm1
Application.Quit
End Sub
I have Workbook named Test. And in The Test I have code that runs when the workbook is opened it shows me UserForm1 which asks me to login with username and password and it will hide applications so only the UserForm1 is seen. The problem is that you can open Excel again and open a new workbook, and there you can go to the VBA and see workbook Test's code and close or modify it.
If the login would be requested in the input box, you can not do the trick and circumvent the login part. Input Box allows you only click in the workbooks Input Box you can't press ALT + F11 and go to VBA code or if you try to open new Workbook and in there goto VBA code there wouldn't be the Test's code. How to do this, with the UserForm?
Thank you so much for all your help in advance!
If it helps I can copy the code to do this , but it's a little mess.
What you want to do is protect your project, then auto execute your macro.
To protect you project do the following:
In your Project Viewer, right click your project then under the protection tab insert your password. You will then need to insert the password when you want to access your script for each instance you have the document open.
I have a custom button (not an add-in, just a "shortcut" button) in Excel's quick access toolbar to run a macro in the active workbook. The workbook is modified and saved daily with a new filename. When the link is first created in the active workbook (call it Version 1) the macro runs fine. However the following day (filename now Version 2) clicking on the macro button opens workbook Version 1 and runs the macro saved in Version 1.
Is there a simple way to break the link and run the macro in the most recent active workbook?
The code is basic - it just opens up a userform and is saved in "ThisWorkbook"
Sub OPEN_DATA_USERFORM()
ufDATA.Show
End Sub
I will try to guide you through this, I hope it helps.
What we need to do is we need to call OPEN_DATA_USERFORM() from our "PERSONAL.XLSB" file. In VB editor screen, in the project explorer you will find a file called "PERSONAL.XLSB", you need to add an "Module" to that and add following code:
Sub KickOff()
Call Application.Run(Excel.ActiveWorkbook.Name & "!OPEN_DATA_USERFORM")
End Sub
By this we will be able to call the userform.show function from our PERSONAL.XLSB which is always running in the background when you open the excel.
PS: I am assuming your OPEN_DATA_USERFORM() is coded in your daily workbook.
UPDATE: PERSONAL.XLSB
Your file should be visible in your project explorer like below:
If it is not there record a dummy macro and select your personal file like below then it should appear in your project explorer in VBA screen:
I have a VBA Macro that I need to run on a CSV file that always has the same name and is always in the same location. Is there a way I can get it to automatically run the macro on the specified csv file as soon as the macro file is opened? Thanks in advance!
Yep, pop it in the Workbook_Open event. To do this open VBA, make sure you can see the Project Explorer, double click on ThisWorkbook, click the drop down that currently says General and change it to Workbook and put your code in there.