How to generate characters in code?

  • Thread starter Thread starter Jan Nademlejnsky
  • Start date Start date
J

Jan Nademlejnsky

I want to create a loop which would open File "TestA.xls", process it, close
it then open "TestB.xls", process it and so on.

Example:

Sub Test()

L= 65 ' Char (L) = Char(65) = "A" '-------< does not work. I need
something similar

For L to L + 5 '5 loops
X = Char(L)
File = "Test" & X & ".xls" '--------TestA.xls, TestB.xls....
Workbooks.Open FileName:=ThisWorkbook.Path & File
Process_It
ActiveWorkbook.Save
ActiveWindow.Close
NEXT

End Sub
________________
Sub Process_It()
-
-
End Sub

Appreciate your help

Jan
 
Jan,

Try something like

aryLetters = Array("L","A","C") 'whatever letters you want
For i = Lbound(aryLetters,1) To UBound(aryLetters,1)
File = "Test" & aryLetters(i) & ".xls" '--------TestA.xls,
TestB.xls
Workbooks.Open FileName:=ThisWorkbook.Path & "\" & File
Process_It
ActiveWorkbook.Save
ActiveWindow.Close
NEXT

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Jan

one way:

Sub Test()
L = 65 ' Char (L) = Char(65) = "A" '-------< does not work. I need
something similar
For X = L To L + 5 '5 loops
File = "Test" & Chr(X) & ".xls" '--------TestA.xls, TestB.xls....
MsgBox File ' for testing
' Workbooks.Open Filename:=ThisWorkbook.Path & File
' Process_It
' ActiveWorkbook.Save
' ActiveWindow.Close
Next
End Sub

Regards

Trevor
 
Thank you very much. This is close to what I was looking for. I would
still prefer something which converts number to characters, for example
=char(65) produces "A" in Excel. I guess, there is no equivalent for
coding it into program.

Jan
 
Jan
still prefer something which converts number to characters

Well, that was exactly what my response gives you ...

L = 65
For X = L To L + 5 '5 loops <<<< actually, that's 6 loops
File = "Test" & Chr(X) & ".xls" '--------TestA.xls, TestB.xls....
MsgBox File

Regards

Trevor
 
Back
Top