PDA

View Full Version : [SOLVED:] Problem while open file script



elmnas
03-16-2015, 06:35 AM
Hi guys I wrote following code to open a file:




Sub LoopFiles()
Dim myPath As String
Dim StrCurrentfile As String
Dim StrFName As String
strDocPath = "C:\Users\daniel.elmnas.TT\Desktop\ko\FIle\Org - Copy\"
StrCurrentfile = Dir(strDocPath & "*NoTrans.xls")
Do While StrCurrentfile <> ""
myNoTransfile = strDocPath & StrCurrentfile
myLangFile = Replace(StrCurrentfile, "_NoTrans", "") ' i want to open this too! HERE
'MsgBox myLangFile
Set myLangFileN = Workbooks.Open(strDocPath & StrCurrentfile)
StrCurrentfile = Dir
Loop
End Sub


Could someone help me to correct the code I can open that file in the loop too?

Thank you in advance

jonh
03-16-2015, 07:54 AM
Sub LoopFiles()
Const myPath As String = "C:\Users\daniel.elmnas.TT\Desktop\ko\FIle\Org - Copy\"
Dim StrCurrentfile As String
StrCurrentfile = Dir(myPath & "*NoTrans.xls")
Do While StrCurrentfile <> ""
If Not InStr(1, StrCurrentfile, "NoTrans", vbTextCompare) Then
Set myLangFileN1 = Workbooks.Open(strDocPath & StrCurrentfile)
Set myLangFileN2 = Workbooks.Open(strDocPath & Replace(StrCurrentfile, "_NoTrans", ""))
End If
StrCurrentfile = Dir
Loop
End Sub