VBA Macro to auto browse and open a file - vba

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.

Related

Creating PowerPoint Add-Ins from VBA defined Macros

So I've created a Macro in a PowerPoint Presentation and I would like to make this Macro readily available to someone else. From what I have gathered, the best way to do this is to create an Add-in.
I have come across several articles stating to do the following, but I am still running into problems:
Open a new PowerPoint Presentation
Create a macro using VBA
Exit VBA, and save the Presentation as a .ppam
Under the Developer Tab, click on the "PowerPoint Add-ins" button
Click the "Add New..." option, and browse for your recently created
.ppam file
Click Load
Click Close
Click Add-ins
You should now see your new Add-in
I have done everything mentioned above and can even see the new Add-in when I select PowerPoint Add-Ins. I'm here because I can't find a way to run the new Add-in, and I don't want it to automatically load on startup or to interfere with the presentation by creating a button on the slides. As instead, I would like to allow the user to run this Add-in from the Ribbon.
Thoughts?
First, save as PPTM. THEN save as PPAM. If you only save as PPAM, you won't be able to go back and edit your code later to correct problems.
To launch your add-in from the ribbon, you must include RibbonX code (a type of XML) to your PPAM or PPTM (best to add it to the PPTM ... it'll become part of the PPAM automatically then).
There's an excellent book on RibbonX that'll save you hours of time:
http://www.amazon.com/RibbonX-Customizing-Office-2007-Ribbon/dp/0470191112
This is a good starting point if you don't want to buy the book:
https://blogs.msdn.microsoft.com/jensenh/tag/all-office-2007-ui-posts/
While you can manually unzip PPTM/PPTX/PPAM files and add the RibbonX code using any text editor, it's silly to do so. Instead use this free tool:
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2009/08/07/7293.aspx

How can I make userform to work like inputbox?

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.

Run Macro on specific static file when macro workbook is opened

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.

How to check if code that is run belongs to active sheet

I have written some code for an excel spreadsheet. This sub has been added to the ribbon using the standard customizations found in File -> Options -> Customize Ribbon. What is funny though, is that the customization will run the Sub on the EXACT EXCEL FILE that the Sub is written in, i.e. the original.
My users copy the excel file and make adjustments and then run the sub (by clicking the customized button in the ribbon), which then opens the ORIGINAL template file and runs the code. This actually works fine - and I like it because it runs the TEMPLATE code on the ACTIVE sheet. But the only problem is it is also OPENING the original template file. How do I get it to close? Remember it is not the ActiveSheet anymore.
One possible answer is to check if the template is open, then close it (using a static reference), but I would prefer something a little more elegant than that.
You should be able to find the template/original using ThisWorkbook.
Also, if you deliver your workbook's code as a .xlam instead of .xlsm, it will be opened, but there won't be a window for it, so users won't see it.
Not sure if you're using this already, but you might also want to use "for this workbook only" when adding ribbon buttons for a .xlam . (Delivering as .xlam allows you to install buttons from a workbook into the ribbon, without relying on file path and without needing your users to also install buttons (they install .xlam instead).)

Excel VBA - Call macro using add in

I have added a toolbar menu for my macro, so I can just press the button and it runs my macro from any excel document. Every time I run the macro though, it opens the source file containing the macro. Is there a way that it won't open the source file and just run the macro? (even opening and closing wouldn't too much of an issue, but I'd prefer not opening it at all)
I haven't been able to find any information about this, so all help to get me started is appreciated.
You can't pull code out of the air to run it; Excel's going to have to open the file the code's stored in to run the code.
If I understand it correctly, you can create an Excel add-in from your code and have the add-in load automatically when Excel starts. Your code will always be available in that case.
This seems like a good place to start:
http://msdn.microsoft.com/en-us/library/aa140990(v=office.10).aspx
USE YOUR PERSONAL MACRO WORKBOOK
Open the VBEditor and find the module containing your macro.
Copy that code.
Now in the VBProject Panel on the left, locate your PERSONAL.XLS or PERSONAL.XLSB project. This is the project where you store macros you want available at all times. Add a module to that project and put your code into it.
Now update your "button" so that it points to the macro in that workbook and you're good to go.
On the off chance your PERSONAL.XLS project does not exist, use the macro recorder to record a "junk" macro and be sure to set it to "Store Macro In: Personal Macro Workbook"... that will create it for you the first time.