How to know when a picture is being selected in Excel with VBA? [closed] - vba

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm new to VBA (1 month), and I can't find how to get my code to know when I select a picture in Excel.
I want to be able to autoselect the cell containing the picture if I select the picture instead of the cell.
The picture already has the same name as the cell with "INV" as start (ex: INV$A$1).
The code must also work for double clicks, as double clicking the cell triggers some subroutine.
Everything is already written, but if I click the picture rather than the cell, nothing happens.

Add a macro to your images when they're inserted. You can use the same macro for all images and check the value of Application.Caller to determine which image/shape was clicked.
Sub Pics_Clicks()
ActiveSheet.Shapes(Application.Caller).TopLeftCell.Select
End Sub

Try something like this:
Private Sub Image1_Click()
MsgBox "clicked via Click!"
End Sub
Private Sub Image1_GotFocus()
MsgBox "clicked via GotFocus!"
End Sub
Here, "Image1" is the automatically created name of a control of type Image.
Such a control is inserted to an Excel sheet in Design Mode. Double click on the control to get the event handler routine auto-edited in the VBA editor.

Related

is the task shown? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 months ago.
Improve this question
I want to find out is the task actual shown or not. (Possible it's not shown by filter, or the outline structure is collapsed)
I want to handle it in VBA.
To determine if a task is visible, all that is really needed is to use the Find method of the Application object which returns True if visible. However, the Find method moves the active cell to that task if found and selects the entire row. This is often undesirable for the end-user.
This function returns True/False depending on if the task is visible, and resets the active cell.
Function TaskIsVisible(uid As Long) As Boolean
Dim curTaskUID As Long
curTaskUID = ActiveCell.Task.UniqueID
Dim curField As String
curField = ActiveCell.FieldName
TaskIsVisible = Application.Find("Unique ID", "equals", uid)
Application.Find "Unique ID", "equals", curTaskUID
Application.SelectCellLeft
Do While ActiveCell.FieldName <> curField
SelectCellRight
Loop
End Function
Note: Any task field can be used with the Find method and the field does not have to be in the current view. Unique ID is best in this case since it's guaranteed to not match any other task.

vb.net - Split Listbox Items [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm having an issue while trying to split some elements of my List Box...
So what I'm doing :
I browse for a text file that contains many Youtube links and
artist/title
All lines from this textfile are added in a Listbox (1st box left on my picture)
By clicking "Next" I want to get only the links without the artist and the titles (that are on the same lines)
Problem is I don't know how to do that...
I already saw this link and this one but can't manage to change it for my project.
I know that a YouTube link is 43 characters.
So what I'm trying to do is :
pick each line of my listbox and take only the 43 first characters (the link)
display each link on each line of my 2nd listbox.
Sorry if there are grammar mistakes, englsih isn't my native language.
Comments in-line
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'put each item in the list box into an array
Dim arrList() As String = ListBox1.Items.OfType(Of String).ToArray
'Trim each item in the array to a length of 43 characters
Dim arrURL() As String = (From url In arrList
Select url.Substring(0, 43)).ToArray
'Add the array as a Range to the items collection of the second list box
ListBox2.Items.AddRange(arrURL)
End Sub

removing the autofilter with command button [duplicate]

This question already has answers here:
ShowAllData method of Worksheet class failed
(7 answers)
Closed 5 years ago.
I have an userform designed with 3 listbox and 2 Buttons.
by selecting the item in the listbox and the button1, i get the filetred result of sheet.
With the command button2, i would like to remove the filter used and get back to the original sheet.
I used the below code,
Private Sub CBExit_Click()
Sheets("Data").ShowAllData
Unload Me
End Sub
with this everytime i get an error message that
showalldata method of worksheet class failed
How can I overcome this error ?
I wanted to clear the filter result and get back to the original sheet with the command button.
any lead would be helpful
If you want to remove all filters then try Cells.AutoFilter

Toggle Spelling & Grammar programatically in Word (Microsoft Office) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
It would help if there is a way to toggle the underlining on and off programmatically, assigning the command to a button to enable me to toggle with a single click.
It is a pain to go through the menus every time I want to do it currently.
How do I do this?
Create two macros. One to turn on and one to turn off Spelling and Grammar as you type.
In Microsoft software, you are able to record a sequence of actions and assign them to a button or keyboard shortcut
Follow these steps precisely to create the ones specific to this solution.
Macro 1: Spelling off
Click View > Macros > Record macro
Type "spelling_off" into the Macro name field (Spaces aren't permitted so use underscore _ character) and click the hammer button.
Click 'Normal.NewMacros.spelling_off' and then the 'Add >>' button
Click 'Modify...' and choose a graphic and click OK. (I choose the red square)
Click OK in the Word Options screen.
Click Review > Language > Language preferences > Proofing
Uncheck 'Check spelling as you type'
Uncheck 'Mark grammar as you type'
Click OK
Click View > Macros > Stop Recording
The macro code will look like this:
Sub spelling_off()
'
' spelling_off Macro
'
'
Options.CheckGrammarAsYouType = False
Options.CheckSpellingAsYouType = False
Application.ScreenRefresh
End Sub
Macro 2: Spelling on
Click View > Macros > Record macro
Type "spelling_on" into the Macro name field and click the MC Hammer button.
Click 'Normal.NewMacros.spelling_on' and then the 'Add >>' button
Click 'Modify...' and choose a graphic and click OK. (I choose the green square)
Click OK in the Word Options screen.
Click Review > Language > Language preferences > Proofing
Check 'Check spelling as you type'
Check 'Mark grammar as you type'
Click OK
Click View > Macros > Stop Recording
The macro code will look like this:
Sub spelling_on()
'
' spelling_on Macro
'
'
Options.CheckGrammarAsYouType = True
Options.CheckSpellingAsYouType = True
Application.ScreenRefresh
End Sub
...and that's it!
Where do the buttons appear?
The buttons appear in the top left hand corner of Microsoft Word.

How do I use TextChanged event in VBA visio?

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