How to use .GetOpenFilename in For loop?

  • Thread starter Thread starter Milind
  • Start date Start date
M

Milind

I need the user to select his file, and am using the
..GetOpenFilename format. However, I need to use the following:

For each c in workbooks("filename"). ...

What to do about the reqd quotation marks around the filename, and what to
do about the "\" path marks which excel does not recognise?

Milind
 
Milind,

Are you trying to lop through the sheets in the workbook you have just
opened? If so, you don't need a filename, you can use ActiveWorkbook, like
this

Dim fileToOpen

fileToOpen = Application _
.GetOpenFilename("Microsoft Excel Files (*.xls), *.xls")
If fileToOpen <> False Then
For Each c In ActiveWorkbook
'DO SOMETHING
Next
End If
 
fname = GetOpenFilename()
sBkName = dir(fname)
workbooks.open fname
for each c in Workbooks(sBkName).Worksheets


or set a reference to it when it is opened.
Dim wkbk as Workbook
fname = GetOpenFilename()

set wkbk = workbooks.open( fname)
for each c in wkbk.Worksheets

Regards,
Tom Ogilvy
 
Back
Top