Part of a file name as a variable

Dryver14

Well-known Member
Joined
Mar 22, 2010
Messages
2,396
Good evening.....(again)

I am looking to open a file weekly the file is

Filename week 17.xlsx

I would like to be able to collect the week number from either an imput box or userform, I have not decided which yet.

It is only setting the week number into the file.open procedure I am unsure of.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try This Code To Do The Job By an Inputbox.
Code:
Sub OpenFile()
Dim i As Integer
i = InputBox("Type a Week Number To Open The File", "Open File")
If i = 0 Then
   MsgBox "You Should Enter a Week's Number"
   i = InputBox("Type a Week Number To Open The File", "Open File")
End If
Workbooks.Open "Week " & i
End Sub
ZAX
 
Upvote 0
ZAX,
Cheers for that,

the path is like R:BBD\BB\Sites\common\TAM\week 17.xlsx
so would I put

R:BBD\BB\Sites\common\TAM\"week "& i.xlsx ?
 
Upvote 0
As a follow up to the above,

Do I need to open the workbook to copy and paste from it?
 
Upvote 0
As For The First Question ,Yes You Would And For The Second One ,Also Yes ,But You Can Tell The Macro To Open The Workbook ,Copy The Range ,Close The Workbook And Paste The Range.
ZAX
 
Last edited:
Upvote 0
OK,

I have been trying this all day:

workbooks.open filename:= "R:\BBD\BB\Sites\Trunking\TAM\Bradford\"Bradford TAM Wk " & i.xlsm"

As soon as the appostophies are around the week it goes daft. (won't accept it, "so it's me that's going mad really")

The input box gives the week number which I allocate to i.

How can I get the workbook open to recognise Bradford TAM Wk 15 as Bradford TAM Wk i ?

A virtual pint to the person who puts me out of my misery.....or send a bullet and a gun, that will suffice.


Thanks in advance
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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