Using a variable as part of workbook name

stakar

Active Member
Joined
Mar 6, 2004
Messages
333
Hi there!!
I have a problem that i cant solve and i want your help.
I want to refer a workbook's name into a messagebox using a variable to assign each workbook

---------------------------------------------------
Sub x()
Dim i As Long

Dim wbName_1 As String
Dim wbName_2 As String

wbName_1 = "Test_1.xlsx"
wbName_2 = "Test_2.xlsx"

Dim PathName As String

For i = 1 To 2
PathName = MsgBox("c:\Test\" & wbName_ & (i))
Next i
End Sub

----------------------------------------------------

The result that i want to see on the screen is the "c:\Test\Test_1.xlsx" and for the next one "c:\Test\Test_2.xlsx".
Instead i get the "c:\Test\1" and the "c:\Test\2"

Thanks in advance!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi there!!
I have a problem that i cant solve and i want your help.
I want to refer a workbook's name into a messagebox using a variable to assign each workbook

---------------------------------------------------
Sub x()
Dim i As Long

Dim wbName_1 As String
Dim wbName_2 As String

wbName_1 = "Test_1.xlsx"
wbName_2 = "Test_2.xlsx"

Dim PathName As String

For i = 1 To 2
PathName = MsgBox("c:\Test\" & wbName_ & (i))
Next i
End Sub

----------------------------------------------------

The result that i want to see on the screen is the "c:\Test\Test_1.xlsx" and for the next one "c:\Test\Test_2.xlsx".
Instead i get the "c:\Test\1" and the "c:\Test\2"

Thanks in advance!
TRY THIS

PathName = MsgBox("c:\Test\ wbName_ "& (i))
 
Upvote 0
Use an array:

Code:
Sub x()
    Dim i As Long
    Dim wbName(1 To 2) As String
    wbName(1) = "Test_1.xlsx"
    wbName(2) = "Test_2.xlsx"
    Dim PathName As String
    For i = 1 To 2
        PathName = MsgBox("c:\Test\" & wbName(i))
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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