Advice to call a code

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I have a msgbox where No closes it but i would like when Yes is clicked it will Call say the below to run it


VBA Code:
Private Sub DHLBUTTON_Click()
ActiveWorkbook.FollowHyperlink Address:="http://www.dhl.co.uk/en/express/tracking.html", NewWindow:=True
End Sub

can you advise the correct way to wright it please
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
VBA Code:
Private Sub PressMyButton()

If MsgBox("Please press Yes or No!", vbYesNo, "Make your choice") = vbYes Then
    DHLBUTTON_Click
End If

End Sub
 
Upvote 0
Afternoon,

This is the code in use.

VBA Code:
Private Sub ListBox1_Click()
  Dim answer As Integer

  Range("A" & ListBox1.List(ListBox1.ListIndex, 1)).Select
  MsgBox "OPEN DATABASE ?", vbYesNo + vbCritical, "OPEN DATABASE MESSAGE"
If answer = vbYes Then
    ???????
Else
    Unload DatabaseNameSearch
End If
End Sub

Where you see the ????? this is where i need to Call Private Sub Worksheet_BeforeDoubleClick

Just cant seem to do anything today
 
Upvote 0
I don't think you can call Private Sub Worksheet_BeforeDoubleClick - this is an event code and only gets called when you double click.

However, whatever code you are calling in that Private Sub Worksheet_BeforeDoubleClick, just call that where you have your "?????"
 
Upvote 0
OK
So if i use the same code but have it run without the double click,.
If this was code to run etc without double click how would it run when YES is selected.


I have this now but after i select YES the userform closes & thats it.
The code added doesnt do anything.

I cant see why this is so hard.

VBA Code:
Private Sub ListBox1_Click()
  Dim answer As Integer

  Range("A" & ListBox1.List(ListBox1.ListIndex, 1)).Select
  MsgBox "OPEN DATABASE ?", vbYesNo + vbCritical, "OPEN DATABASE MESSAGE"
If answer = vbYes Then
    If Intersect(Range("A6", Cells(Rows.Count, "A").End(xlUp)), Target) Is Nothing Then Exit Sub
    Cancel = True
    Database.LoadData Me, Target.Row
Else
    Unload DatabaseNameSearch
End If
End Sub
 
Upvote 0
Because in your code, you are saying
VBA Code:
If answer = vbYes Then
... but you haven't set the value of answer.

Try a small modification:

VBA Code:
Private Sub ListBox1_Click()
  Dim answer As Integer

  Range("A" & ListBox1.List(ListBox1.ListIndex, 1)).Select
  answer=MsgBox()"OPEN DATABASE ?", vbYesNo + vbCritical, "OPEN DATABASE MESSAGE")
If answer = vbYes Then
    If Intersect(Range("A6", Cells(Rows.Count, "A").End(xlUp)), Target) Is Nothing Then Exit Sub
    Cancel = True
    Database.LoadData Me, Target.Row
Else
    Unload DatabaseNameSearch
End If
End Sub
 
Upvote 0
Syntax error with this

VBA Code:
answer=MsgBox[COLOR=rgb(184, 49, 47)]()[/COLOR]"OPEN DATABASE ?", vbYesNo + vbCritical, "OPEN DATABASE MESSAGE")

Now when run i see RTE 424Object Required

This in yellow
Code:
If Intersect(Range("A6", Cells(Rows.Count, "A").End(xlUp)), Target) Is Nothing Then
 
Upvote 0
OK
Plan B

This works fine but a slight edit & it will be ok.

Code:
Private Sub ListBox1_Click()
  Dim answer As Integer

  Range("A" & ListBox1.List(ListBox1.ListIndex, 1)).Select
  answer = MsgBox("OPEN DATABASE ?", vbYesNo + vbCritical, "OPEN DATABASE MESSAGE")
   If answer = vbYes Then
    Database.Show

Else
    Unload DatabaseNameSearch
End If
End Sub

Lets say i select Tom Jones in the listBox.
I then see the MsgBox
I select YES
Then the DATABASE opens up.

So far so good.

On this userform is a comBobox called ComboBoxCustomersNames


Now if you manually select a name from this ComboBox it will do what i require.

SO
The edit would be for the ListBox selection to then select the same name in the userform ComboBox.

Did i explain ok ?

Thanks
 
Upvote 0
If its easier for you.
The customers name is also selected in column A
Then the userform DATABASE opens.

So remember the selection in Column A & use that to select from the comboBox ?
 
Upvote 0
Syntax error with this

VBA Code:
answer=MsgBox[COLOR=rgb(184, 49, 47)]()[/COLOR]"OPEN DATABASE ?", vbYesNo + vbCritical, "OPEN DATABASE MESSAGE")

Now when run i see RTE 424Object Required

This in yellow
Code:
If Intersect(Range("A6", Cells(Rows.Count, "A").End(xlUp)), Target) Is Nothing Then
for some reason there was an additional ")" in the line I adjusted, sorry! Should have read:

VBA Code:
answer=MsgBox("OPEN DATABASE ?", vbYesNo + vbCritical, "OPEN DATABASE MESSAGE")
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top