Wild cards in VBA

Dan71

New Member
Joined
Jul 31, 2006
Messages
48
Good morning all.
I am using this function in VBA

Windows("buying report week 20.xls").select

It works fine but I want to change it so that I can use a wild card as the week number changes. I have tried verious diferent permutations but can't get it to work. I assume it is fairly simple.
Can you help please.
Dan
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi Dan

A good idea would be to set the workbook name as a string variable and also hold the week number in a separate integer variable then pass this to the Windows collection:

Code:
Dim strFile As String, iWeekNum As Integer
iWeekNum = Sheets("Sheet1").Range("A1").Value
strFile = "Buying Report Week" & iWeekNum & ".xls"
Windows(strFile).Activate

You can assign the week value to iWeekNum in a variety of different ways - the above is an example of how you might do so from a worksheet cell.

Hope this helps!

Richard
 

Dan71

New Member
Joined
Jul 31, 2006
Messages
48
Thanks Richard, I suppose I wll have to do that. I had hoped that I would not need to put in the week number and keep it really simple. Oh well.
Dan
 

Forum statistics

Threads
1,141,757
Messages
5,708,349
Members
421,566
Latest member
7Nabisco

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