VBA code opening workbook with a userform, need to select drop down menu choice: how ?

totalnatal

New Member
Joined
Jun 9, 2010
Messages
33
Hi,

I have a workbook (wkbk A let's call it) with a VBA macro that runs automatically to grab some data from wkbk B.

The macro is designed to open wkbk B, on the userform select "London" from a drop down menu, click on the "OK" button on the user form, press some other button to refresh data, copy paste data of wkbk B and close wkbk B without saving.

I have everything working, except the part where I open wkbk B and then the userform comes up but I do not know what to write in my VBA to select "london" from the drop down menu and click ok.

I've tried to record the macro but it comes up as blank essentially.

Any ideas ? Thanks a lot guys.
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,701
Office Version
  1. 2016
Platform
  1. Windows
Have you create the userform in the second workbook? What you can then do, in the workbook vba you set the userform to open when the workbook is opened, and then when you add your code to open the workbook the form is opened as well. If you have the combo created you can popluate it with Add Item and set the Default to London if that is the main choice.

Code:
Sub checkmeOut()
Dim wkbkB As Workbook
Set wkbkB = Workbooks.Open("M:\Testing1.xlsm")
End Sub
 

totalnatal

New Member
Joined
Jun 9, 2010
Messages
33
Have you create the userform in the second workbook? What you can then do, in the workbook vba you set the userform to open when the workbook is opened, and then when you add your code to open the workbook the form is opened as well. If you have the combo created you can popluate it with Add Item and set the Default to London if that is the main choice.

Code:
Sub checkmeOut()
Dim wkbkB As Workbook
Set wkbkB = Workbooks.Open("M:\Testing1.xlsm")
End Sub

wkbk B which contains the form opens with the userform directly opening also. Though it opens in READ only always.

What is this Add Item thing you were talking about that looks like the solution. thanks
 

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,701
Office Version
  1. 2016
Platform
  1. Windows
Behind the userform you have events and if you select Initialize or Activate you can then add the code to fill the combo box something like this, or you can tell it to select from a range of cells.

Code:
Private Sub UserForm_Initialize()
With Me.cboTown
    .AddItem "London"
    .AddItem "Birmingham"
    .AddItem "Leeds"
End With


End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,905
Messages
5,598,778
Members
414,259
Latest member
beetle12

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
Top