ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening files with variable names (https://www.excelbanter.com/excel-programming/425060-opening-files-variable-names.html)

Brad

Opening files with variable names
 
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?

Ritwik Shukla[_2_]

Opening files with variable names
 
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



All times are GMT +1. The time now is 08:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com