assign combobox value to variable in vba

met1713

New Member
Joined
May 27, 2015
Messages
10
I cant quite figure it out and tried everthing, im assigning a value and then this value declares what workbook it opens in a folder, my comboboxes are on the excel sheet and not in a pop up user form if it makes any difference

what i have so far

dim RandomName as String

RandomName = Me.cboRandomName

"......\friends\RandomName.xlsx"
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try :

Code:
RandomName = Me.cboRandomName[COLOR=#FF0000].Value[/COLOR]
 
Upvote 0
already tried it, the input is in the form ###-#### so idk if declaring as a string is effecting it or what, but it is giving me application-defined or object-defined error message box.
 
Upvote 0
Have you tried setting a watch on Me.cboRandomName and checking all of its properties at the point in the code where you try to assign the selected value to the string variable?
 
Upvote 0
when i scroll over me.cborandomname.value it says me.cborandomname.value = "###-####" but when i go over randomname it says randomname = "", if thats what you mean by a watch
 
Upvote 0
btnSearch_click(), my search button click event, but its the code behind my sheet3 where my program is at
 
Upvote 0
i changed it
Dim RandomName As Integer
RandomName = 6

and I scrolled over and it said RandomName = 0 if that helps at all
 
Upvote 0
You really need to get to grips with debugging if you want to code in VBA. It is pretty much the most essential part.

In the VBA Editor window (where you see the code behind your sheet), go to View > Watch Window

(It's typically displayed by default anyway, as a separate window below your code)

Right-click in the window, select Add Watch... and put Me.cboRandomName as the Expression and hit OK

Step through your code line-by-line and pause / breakpoint on the line where you apply the value in the combobox to the string variable. Your code is now 'paused' at this point so you can see what value Me.cboRandomName holds (as well as all it's other various properties) Expand the watch item and scroll down to its Value property. What value is it holding at this point?
 
Upvote 0
Haha I am so close the variables are changing like i want them to, but the page will still not open the code is

workbook.open ".....\folder\randomname"

the .xlsx is built into the randomname variable and i have tried it both ways and made sure the path was correct. Not sure if you can help with this but thank you with the help so far
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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