K
K
Hi all, I have macro set on a button (see below)
***************************************************>
Sub OpenFile2()
Folder = "C:\Document\KK"
VRNumber = Range("A1").Value
fName = Dir(Folder & "\*" & VRNumber & "*.xlsx")
If fName = "" Or Range("J51").Value = "" Or Len(VRNumber) <> 6 Then
MsgBox "VIREMENT *" & VRNumber & "* DONT EXIST"
Else
Workbooks.Open Filename:=Folder & "\" & fName
End If
End Sub
<***************************************************
In Folder "C:\Document\KK" files names are like (see below)
Excel 553656.xlsm
Excel 556987 - Page 1.xlsm
Excel 556987 - Page 2.xlsm …… etc
I want two amendment in macro above. At the moment if I put 6 digits
number in cell "A1" which are in file name (mentioned above) and hit
the button then macro opens that file for me. The first amendment I
want is to specify that only 6 digits numbers should be put in cell
"A1" by adding code line in above macro "Mid(fName,7,6)" so if some
one put 6 digits like "Excel " macro should not open the file and it
should only open if the middle bit of file name which are 6 digit
numbers will be put in cell "A1". The second amendment i want in
above macro as the last two files mentioned above got same 6 digits
number in their names, the only difference is the last bit which is
"Page 1" and "Page 2" so if i put 6 digits number which is "556987" in
cell "A1" and when I hit the button then macro should open all the
file which got that 6 digits number in their names. I tried many
experiments but wasnt very successful. Can any friend amend my macro
above and put these two amendments. it will be much appricated.
Thanks in advance
***************************************************>
Sub OpenFile2()
Folder = "C:\Document\KK"
VRNumber = Range("A1").Value
fName = Dir(Folder & "\*" & VRNumber & "*.xlsx")
If fName = "" Or Range("J51").Value = "" Or Len(VRNumber) <> 6 Then
MsgBox "VIREMENT *" & VRNumber & "* DONT EXIST"
Else
Workbooks.Open Filename:=Folder & "\" & fName
End If
End Sub
<***************************************************
In Folder "C:\Document\KK" files names are like (see below)
Excel 553656.xlsm
Excel 556987 - Page 1.xlsm
Excel 556987 - Page 2.xlsm …… etc
I want two amendment in macro above. At the moment if I put 6 digits
number in cell "A1" which are in file name (mentioned above) and hit
the button then macro opens that file for me. The first amendment I
want is to specify that only 6 digits numbers should be put in cell
"A1" by adding code line in above macro "Mid(fName,7,6)" so if some
one put 6 digits like "Excel " macro should not open the file and it
should only open if the middle bit of file name which are 6 digit
numbers will be put in cell "A1". The second amendment i want in
above macro as the last two files mentioned above got same 6 digits
number in their names, the only difference is the last bit which is
"Page 1" and "Page 2" so if i put 6 digits number which is "556987" in
cell "A1" and when I hit the button then macro should open all the
file which got that 6 digits number in their names. I tried many
experiments but wasnt very successful. Can any friend amend my macro
above and put these two amendments. it will be much appricated.
Thanks in advance