From: Gordon Rainsford on
I have some code that includes the line:

Set shRanks = Workbooks("Ranks.csv").Sheets("Ranks")

The problem is that the file I need to set as shRanks may have an
integer in its name - eg "Ranks17.csv"

How best can I do this?
From: joel on

A CSV file is only one sheet since it is really just a text file. The
sheet name is always the same as the workbookname. the best solution is
just to use the first tab.

from
Set shRanks = Workbooks("Ranks.csv").Sheets("Ranks")


to

Set shRanks = Workbooks("Ranks.csv").Sheets(1)



I don't think this is going to work since the workbook name is also
wrong. I would need to see the statement you use to read the CSV file.
If you are using workbook open then try this


fileToOpen = Application _
.GetOpenFilename("Excel Files (*.xls), *.xls")
If fileToOpen = False Then
MsgBox("Cannot Open file - Exiting Macro")
exit sub
End If

Set bk = workbooks.open(filename:=fileToOpen)

Set shRanks = bk.Sheets(1)


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=170681

[url="http://www.thecodecage.com"]Microsoft Office Help[/url]

From: Gary''s Student on
Sub demo()
Dim shRanks As Worksheet
Dim n As Integer
n = 17
Set shRanks = Workbooks("Ranks" & n & ".csv").Sheets("Ranks")
End Sub

--
Gary''s Student - gsnu200909


"Gordon Rainsford" wrote:

> I have some code that includes the line:
>
> Set shRanks = Workbooks("Ranks.csv").Sheets("Ranks")
>
> The problem is that the file I need to set as shRanks may have an
> integer in its name - eg "Ranks17.csv"
>
> How best can I do this?
> .
>
From: Gordon Rainsford on
I must have been unclear.

There will be a worksheet open, whose name is "Ranks**.csv" where ** are
wildcards. I want to set that worksheet as shRanks, whatever the value
of **,

Thanks,

Gordon

Gary''s Student <GarysStudent(a)discussions.microsoft.com> wrote:

> Sub demo()
> Dim shRanks As Worksheet
> Dim n As Integer
> n = 17
> Set shRanks = Workbooks("Ranks" & n & ".csv").Sheets("Ranks")
> End Sub
From: Dave Peterson on
Maybe you can set the variable right after you open the .csv file.

Dim scvwks as worksheet
dim CSVWkbk as workbook

set csvwkbk = workbooks.open(filename:="c:\ranks.csv")
set csvwks = activesheet



Gordon Rainsford wrote:
>
> I have some code that includes the line:
>
> Set shRanks = Workbooks("Ranks.csv").Sheets("Ranks")
>
> The problem is that the file I need to set as shRanks may have an
> integer in its name - eg "Ranks17.csv"
>
> How best can I do this?

--

Dave Peterson