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"
 
So the value held in Me.cboRandomName - which is subsequently passed to the RandomName string variable - is a path to a workbook which you want to open? Or just the name of a folder / subfolder? If not, how do you derive the full path of the workbook you're trying to open from the combobox?
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Code:
Dim wbk As Workbook

Set wbk = Workbooks.Open(Me.cboRandomName.Value)

With wbk
    ...
End With
 
Upvote 0
so i have a master folder that has 6 subfolders and those folders have 64 subfolders and then there are several excel sheets with in those 64 subfolder and basically my excel program has variable inputs (comboboxes) for each folder subset and the excel sheet
6 subfolders - combobox with all the names in subfolder
64 subfolders - combobox with all names in subfolder
excel files - combobox with all excel files


so basically the code looks like

workbook.open ".....\masterfolder\6subfolders\64subfolders\excelfiles.xlsx"
 
Upvote 0
i figured it out i need "" and & breaking up my file path and variables. Thanks for your help!!!
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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