I'm trying to develop a simple program which will show a form with a listbox and a button. The buttom will allow a listbox entry to be selected and close the form. The entry will them be sent to the previous open application.
For example, I could select my postcode from the listbox and have it sent to the currently selected field in my internet browser. Or the current date to my text editor.
This is what I have, which doesn't work, it seems to bring up my task bar.
Module Module1
Sub Main()
Form1.ShowDialog()
SendKeys.SendWait("fred") 'I'll substitute fred later.
Application.Exit()
End Sub
End Module
I intend to create a shortcut and a ssign a hot key to start the program, i'm justing running it from the ide at the moment.
Any suggestions ?
Have a look at this tool AutoIt - http://www.autoitscript.com/site/autoit/
Related
I've gone through a number of tutorials and instructional videos trying to achieve my intended result of simply allowing a checkbox in my form to hide content when selected, or re-show it when being de-selected, but nothing seems to be working.
Currently, I've created a bookmark for the content I want hidden, and try to call his this in VBA with the following statement - which a number of resources indicated as the solution:
Private Sub CheckBox1_Click()
ActiveDocument.Bookmarks("bookmark").Range.Font.Hidden = CheckBox1.Value
End Sub
But despite doing this, selecting the checkbox has no affect on the content.
Is there something additional I'm missing (I'm using Microsoft Word 2013).
Your code worked fine when I tested it, but I ran into a few issues since I've never messed with userforms/checkboxs in Word VBA and I suspect you may have the same.
For instance, the first thing I did was create Insert --> Module. This is incorrect. What you want to do is Insert --> Userform then drag a checkbox over from the ToolBox
https://smallbusiness.chron.com/use-check-boxes-word-54673.html
Then double click the checkbox to bring up the "module" it would run, notice there is no module in the side pane! Edit the module, then go back to the userform and press F5. You should be presented with a checkbox that will hide/unhide your text.
Here is my module:
Public Sub CheckBox1_Click()
ActiveDocument.Bookmarks("bookmark").Range.Font.Hidden = CheckBox1.Value
End Sub
Here is an image:
Note: I didn't test how to insert the checkbox into the word doc, I'll leave you some of the learning!
Update:
This sub will make the CheckBox appear when run, but I'm not sure the logic you would use to call it, perhaps an event like opening of document?
Sub Loadform()
Load UserForm1
UserForm1.Show
End Sub
This could be called via a keyboard shortcut or event, but this will cause a "pop-up window". If you want an inform checkbox you may need to look into using this Legacy Form/Checkbox. I was following the URL from above but I think it's dated.
Update:
You could also add this easily to a toolbar, but that isn't likely what you want. I found the best way is to use a "field code" see --> https://word.tips.net/T001571_Assigning_a_Macro_to_a_Button_in_Your_Text.html
I was able to get this to work by pressing CTRL + F9 then typing { MacroButton Loadform ClickMe} then clicking this text. This may be the best bet as using an image seems not to be a great idea.. (https://answers.microsoft.com/en-us/msoffice/forum/all/using-graphic-with-macrobutton/a9c1ef3b-cf1f-48ba-92a8-c44bffcdc131) & (http://www.addbalance.com/usersguide/parts/macrobutton_fields.htm#Different_behavior)
Gif Example:
I work with a software which has no loading window/picture, so when I run it, I don't know exactly when it starts to run. Though I can monitor the running .exe task in taskmanager I want to create a 'loading window' in VBA to make the loading process more visible. I think a possible way to achieve this is to write a simple macro which contains the shell(.) command and a testing condition (eg. if a counter counts to 130 then close the form automatically end if). The problem is when I try to use Unload Me, it can not be used unless it is a part of a click event. Here is my code which opens my form:
Sub Loadpic()
LPic.Show
End Sub
you can use this
Unload LPic
Do Events
You can find the formname in the properties dialog ( Press F4 when looking at the form)
I am creating a Word Addin using Visual Studio 2008 with Visual Basic language. I have created a custom ribbon group and a button name "Show_Form". I want that when I click on that button a windows form named "Form" will show.
Sub Button1_Click()
Form.show()
End Sub
It showing a error. Can you please help me.
There is no form called "Form"
You will need to do Form1.Show or Form2.Show etc
However it is good practice to name the forms to what they will be used for otherwise it can become difficult to understand the program code if everything is named so that it doesn't actually identify what it does.
I have written a form based document generation macro (in VBA) for distribution to a sales team.
For their ease of use, I want to provide a self-contained file which will display the form as soon as the document is opened.
Using AutoOpen I can get the form to display as intended if word is already open and the dotm file is opened within. However, if I double click the file from within explorer, nothing happens and I have to launch the macro manually. I thought AutoExec might allow this but no luck there. I've spent considerable time trying to get this to work through googling etc. but I'm not getting anywhere.
How can I make the form display even when the file is opened with a double click? Is it possible to do this without having to change normal.dotm for each user?
For further background, I am using Word 2013 with macros fully enabled during testing. The dotm file is stored in a trusted location.
I am using a macro to launch the form like this...
Public Sub AutoOpen()
StartPage.Show
End Sub
I have tried using AutoExec as well to no avail.
In the "generator.dotm" file got to Visual Basic and go in to the "ThisDocument" Microsoft Word Object.
At the top of the Visual Basic Editor select "Document" in the left hand side and then click on "New" on the right hand side. Private Sub Document_New() method will appear for you to be able to edit. Then you can call your userform in there. Similar to:
Private Sub Document_New()
Dim myForm As UserForm1
Set myForm = New UserForm1
myForm.Show
End Sub
Save your Generator.dotm and double click it through Windows explorer and you should get the results that you would like.
I'm using Visual Studio just to create GUIs for a project. There is no code, only the designs.
I need to convert these forms into images that I can paste into the report.
Is there a simple way to do this?
Thanks.
Edit: the only solution I have so far is to edit the project so that each window I want to export is the start up form, but I am going to have over 40 forms, so this will get tedious after awhile.
Create a new Class in your Projects, lets say Startup.vb, which looks something like this:
Friend Class Startup
<STAThread()> _
Public Shared Sub Main()
Application.Run(New Form1)
Application.Run(New Form2)
Application.Run(New Form3)
End Sub
End Class
In the Project Properties the general Tab, untick Enable application framework and choose Startup as new start-object.
Obviously you'd need to adjust your startup class to open all forms you wish to open. When running the application just press Alt+PrintScr to copy an image of just the selected Window/Form to the clipboard. Paste that back into the paint application of your choice. Microsoft Paint will do.
Using a screen capture program might be your best choice. Personally I recommend TechSmith SnagIt application. You can capture any selected region in the screen using this application.
If you right click on the form a select Lock Controls this will remove the resize handles you can then press PrtScn to take a copy.
Note: After applying Lock Controls it does still have a focus rectangle and lock symbol but these are outside the co-ordinates of the form so they could be cropped in MS Paint or similar?