Opening files with variable names

B

Brad

I'm looking for code to open an excel workbook with a variable name. The file
name should be fairly constant except there will be a revision level on the
end of the file name. For example, C:\Excelfile rev.01.

Is there some code to open a filename containing a phrase?
 
R

Ritwik Shukla

Open any module and paste the codes they are read through the comments

Function WorkbookOpen(Mydir As String, WorkBookName As String, VC As String)

' by Ritwik Shukla
' MyDir is path of directory
' My workbbok name is standard name of the excel workbooks
' VC is version control



fullpath = Mydir & "\" & WorkBookName & VC & ".xls" ' Your full path

Workbooks.Open fullpath


End Function

Testing This function :

Lest say you have 4 file stored in C:\Manyfile folder and names are
test1.xls, test2.xls and so on


Sub openbookTest()

Dim N As Integer ' VC as Integer
Dim I As String ' Vc as String

For N = 1 To 4 ' You can set this value vy counting files in folder
' visit http://www.ozgrid.com/forum/showthread.php?t=51500

I = N

Call WorkbookOpen("C:\Manyfile", "Test", I) ' Calling function

Next N

End Sub
 

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