I have setting up the environment of programming the VBA Editor.
And I have a button on sheets("1"), after I click this button, I want to add the following code to sheets("2"), which sheets("2") already have some code. The code I decided would stored into string format.
Case "ABC:
...
...
...
...
End With
I want to add the code into line 15 of the sheets("2") code, but I do know how to write the code. Someone suggest me to read this tutorial http://www.cpearson.com/Excel/vbe.aspx but I cannot understand.
Clarify My Situation:
I have a database about some customer in excel, and with some code such as "case customer_1 ..... case 2 .....", which used to perform a combo box. what I want is when I add new customer in the database, press a button, a new case is automatic done, is that possible?
Can anyone write it to mee?
Friend,
I don't believe you want your button to write code for you. Maybe this is a super advanced program that will write code depending on current state when the button is clicked but I'm assuming, based on your reading material, that you want the button to execute code for you.
In this case write some test code on sheet 2.
Sub testthing()
Msgbox "h3llo world!"
End sub
Then on your sheet one button and assign testthing macro to it.
You linked a button to a macro!
Then, change the macro to perform the desired task. Test it in the project manager. When you are sure it works, change the name and assign it to your button.
This should help, but it may not. I had to do some guesswork from your question. If this doesn't answer your question please add details and we will help you
Related
Hi GUYS , I will explain my problem:
1- I use object command in excel to bring another excel file see image(1)object_image
2- I want to make command button which links to the object
3-image (2) show the worksheets and forms note when I close the book, the object's book change image all
so what I want is when I click the command button in my first excel it will open the form and allow me to change in the second excel.
this is my code
Private Sub CO1_Click()
Workbooks("Book3").Worksheets("Sheet1").CommandButton1.Value = True
Application.Run Workbooks("Book3").Worksheets("Sheet1").OnAction
trainUserForm.Show
End Sub
please, guys, i need this to finish my work and thx :)
Pop up charts in VBA Excel
I was very curious with the answer in the above link.
My question is, Can I pop up a graph with click of button(The button is on Sheet1) and when i go bach to
Sheet thr graph is gone
Pertinent to your question as it is worded in the Title (i.e. 'Can i launch userform from a button in a Sheet'), you can implement this functionality in two simple steps:
1). From Excel 'Developer' tab select Insert -> Button. By default, it will create a new Button1 and corresponding Click event handle will be added to the Module1
Sub Button1_Click()
End Sub
2). Provided that you have a User Form named UserForm1, add a single statement in that event handle that will open the UserForm1 on Button click:
Sub Button1_Click()
UserForm1.Show
End Sub
In case you are trying to implement additional functionality, please include your code snippet highlighting the problematic part.
Hope this will help. Best regards,
Let's do it by point and basing on the answer you have posted.
Can I pop up a graph with click of button(The button is on Sheet1)?
Yes, you can. You need to:
Put a Button on Sheet1 and associate to it a macro, let's say popUpChart;
Create and show the chart:
Sub popUpChart()
Dim ch As UserForm1
Set ch = New UserForm1
'ch.CommandButton1_Click()
'a) Uncomment the line above if you want to invoke the button press before to show the chart
'b) If you decide to uncomment, remember to change the sub from "Private" to "Public"
ch.Show
End Sub
when i go bach to Sheet thr graph is gone
I don't understand well what you mean here. Do you mean "I want the graph to be gone when I go back to the sheet" or "I would like the chart to stay here but actually it's gone?
a) In the first case, it's enough to remove the image from the Image control of the form;
b) In the second case, it's enough to remove the Set statement from the button's macro.
This is related to this question
How do I programmatically/automatically change the text formatting for the text of a Visio shape after I am done with the editing?
There I tried to use some code that would be executed when the text of a shape is edited
For some reasons, as described there, in some situations which I could not isolate the code is executed endlessly.
That is probably because the script calls itself in a loop. The code is supposed to be executed every time the text of the shape is edited BUT the code itself changes the color of the text. I guess that would count as a new text change and so on.
I am thinking about using the event called TextChanged. According with the documentation this should execute the code when the user finished the editing
http://msdn.microsoft.com/en-us/library/office/ff768749.aspx
I could not find a example of using such event in VBA and here is where I need your help
thanks in advance
Uni
This is how I tested:
I used CallThis('ThisDocument.warning") to call the procedure below from "TheText" event of that shape (available via the shapesheet)
Sub warning(oShape As Visio.Shape)
MsgBox ("Text edited")
End Sub
This gets executed like three times if I star editing the text of a shape and I press the space key (adding a space to the existing text)
Ok here is how you do it:
Open the Code editor
In the Project explorer select "ThisDocument"
Next in the ObjectWindow select Document
Then in the Method dropdown box select ShapeExitedTextEdit
You will see a skeleton procedure like below
Private Sub Document_ShapeExitedTextEdit(ByVal oShape As IVShape)
End Sub
There is where you add the code that you want to be executed every time when the editing if finished
I'm building a form in Adobe Livecycle and would like all negative numbers to display in red. I can accomplish that on individual elements by attaching this code to the exit event:
form1.#subform[0].Table3[0].HeaderRow.concessions1::exit - (FormCalc, client)
if ($.rawValue <0) then
$.font.fill.color.value = "255,0,0"
else
$.font.fill.color.value = "0,0,0"
endif
Currently I have to add this code to every single field, is there a way to make this script run on multiple fields without retyping it for each one?
Thanks
your options are:
Externalize the code in a script object and call the method on the exit event. You can pass the field as an input parameter so that your code is generic.
If you want to do this before a form is submitted, you can create a method that loops through your form fields and reference this code to highlight the negative values.
I hope this helps. Let me know if you have any more questions.
Thanks,
Armaghan.
I have a form that I want refreshed when the submit button is clicked. Preferably those that have default values will be restored and those without will be blank.
The submit button has an attached OnClick Macro that, checks to make sure all fields are filled, if so an action query runs that inserts a new row into a table.
So its after this action query that I want the refresh to occur. I have tried researching and come across suggestions that suggest using VBA code Me.Requery or Me.Refresh. I'm not 100% on how to incorporate this into the macro. The RunCode command doesn't recognize the function I put the code in, and The convert macro to VBA option in the top left is grey'd out.
I'm new to Access and just not seeing where the communications are for code and macros if someone could please elaborate for me I would be greatly appreciated.
Please consider my solution as a brief introduction to VBA. If you care to learn the language, you will find there is very little you cannot do.
Within your submit button properties, there should be an 'Event' tab. In this tab, the On Click should be set to [Event Procedure]. Click the three dot button just to the right of that, and it will launch the VBA editor.
All you need to have here between the Private Sub and End Sub lines are these lines of code:
DoCmd.RunMacro ("Mac_1")
Me.TextBox1.Value = "Null"
Me.CombBox1.Value = "Null"
Me.Refresh
MsgBox "Your Save Was Successful.", vbOKOnly, "Saved"
"Mac_1" is the name of the macro you want to execute. the ME.Refresh executes as soon as mac_1 finishes, and will refresh the page. Be sure to enclose it in a proper quote (") and not a double tick ('').
The Requery command can be used from both within VBA code or a macro. It sounds like you are using the macro designer so you can use the Requery macro action instead of VBA.
Just add this to your macro after you have inserted your new data.
This macro action lets you specify a control to requery. The parameter can be left blank to requery the source of the active object. More information can be found here.
Edit
In response to your comments, I think you should try experimenting with the SetProperty macro action (more details here).
I have attached this macro to a button click event and the value from the TextBox called txtInputValue is cleared. The Value field is left blank as you want to fully remove the value from the text box.