show list of wbooks present into a dir

S

sal21

How i can:
insert into MyWbook a button to show into userform the list of wbook
present into c:\mydir\

All wbooks have the name similar:

ESTINTI_4543.xls
ESTINTI_4500.xls
ESTINTI_4501.xls
ESTINTI_4502.xls
ecc....

(Naturally not show into list of the userform the suffix .xls)


After i have clicked on one wbook listed into userform, copy the shee
of wbook clicked, into wbook MyWbook .xls.

All wbooks into dir MyDir contain only one sheet named: DARE_GLO
(EPUR)..
 
D

Dave Peterson

One way...

Option Explicit
Sub testme()

Dim myFolder As String
Dim myCurDrivePath As String
Dim wkbk As Workbook
Dim myFileName As Variant
myCurDrivePath = CurDir

myFolder = "C:\temp"

ChDrive myFolder
ChDir myFolder

myFileName = Application.GetOpenFilename(Filefilter:="Excel Files, *.xls")

ChDrive myCurDrivePath
ChDir myCurDrivePath

If myFileName = False Then
'user hit cancel
Exit Sub
End If

Set wkbk = Workbooks.Open(Filename:=myFileName)

With wkbk
.Worksheets(1).Copy _
before:=ThisWorkbook.Worksheets(1)
.Close savechanges:=False
End With

End Sub

You don't need to build a userform. Excel's VBA has .getopenfilename that you
can use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top