How can I make userform to work like inputbox? - vba

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.

Related

Hidden VBA Code (project locked from viewing ) denies User Form Macro

I think I am facing the same problem asked by Gaus Shaikh in the link below but I have the feeling he was not understood at that time. I try to spend some other words on this topic to help you guys for your support.
I create another question because, in my opinion Gaus question title could be misunderstood.
To recap, we have a problem dealing with an excel macro that generate a user form. Actually, if the VBA project is protected by password the macro works. The weird point is that, if I just hide the code (Visual Basic Editor-> VBA project properties -> protection -> lock project from viewing -> insert pw -> OK), the macro won't works even if the project is not protected by password.
I'm stuck here. I am not able to find a solution. Have you guys have any idea?
(I am using excel 2013)
Thank you in advance!
Gaus Shaikh question:
VBA password protected project not opening userform
N.B:
Basically, any macro which generates a user form gives " run-time error 50289. Project is protected." As an example, the following macro that generate an empty user form fails if the code is hidden and works if the code is shown.
Public Sub goUserForm()
Dim mainframe As Object
'Set main frame
Set mainframe = ThisWorkbook.VBProject.VBComponents.Add(3)
'Show the form
VBA.UserForms.Add(mainframe.Name).Show
End Sub
To fully understand the issue, try this macro on your worksheet, then hide your code. Save, close and open the document. The macro won't work unless you show your code.
Ok, now it's clearer. As the VBA project is protected you will not be able to access it even not with code. Any other code will work.
So, this will not work
Set mainframe = ThisWorkbook.VBProject.VBComponents.Add(3)
VBA.UserForms.Add(mainframe.Name).Show
Code not accessing the VBA project like this will work
UserForm2.Hide
UserForm1.Show

VBA Macro to auto browse and open a file

I am writing a VBA macro to fill a web form with values from spreadsheet.
I have completed macro to fill all form fields except one to click on a button in form to Browse for files.
Below is the macro line to click the browse button.
IE.Document.getElementById("notification_picture").Click
I'm clueless on how to do the next steps i.e. to browse to a particular folder, select and open the file.
Any help is appreciated.
Man... particularly deal with IE is a pain...
You could use
Sendkeys "%S"
It will save it in Downloads folder and then you can move it, open or do whatever you want.
Many will say it is not good to use it because if the user change the focus while the macro is running it will not working, but it is the simplest way.

View the Visual Basic Code (VBA) when the workbook is closed on launch of the same workbook

By mistake I wrote code that will close the workbook when it is opened.
Because of this I am unable to see the code in order to fix it. How do I edit the code?
open Excel, go in and disable macros from the Trust Center, then open your workbook and remove the offending line of code.
http://office.microsoft.com/en-gb/excel-help/enable-or-disable-macros-in-office-documents-HA010031071.aspx
Try opening some workbook and click alt + F11 to see the macro window. Then open your workbook and it should be ok.
Alternatively, try switching off the macros in Excel so that no macros could run. Then open your workbook.

New VBAproject open prevention

I have a excel report that has VBA code written.When i try to view code, alongwith my code that is under display a new project VBAproject(Book 1) opens.Using this new workbook code can be written that changes my values in excel.I cannot set Userinterfaceonly to false as this doesnt allow the internal VBA to run.
Can the VBAproject(book 1) that opens alongwith my code under display be prevented/locked so that no new code can be written?
You can set a password on VBA associated with a workbook.
Open the VBA editor for the workbook you want to protect. Select the project, and go to the Tools Menu, then the VBAProject Properties option. Clicki the Protection tab, and set the password, confirm it, click OK. Save the workbook.
Now if you try to open the VBA for that workbook you'll be prompted for the password, but the VBA can still be called.
PS Don't forget the password!

Can excel macro run on browser?

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.