Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
Is there a way to make Constants as Arrays? Something like: Public Const Doc(1) As String = "Rules.DOC" Public Const Doc(2) As String = "Personal.DOC" Public Const Doc(3) As String = "Reporting.DOC" etc... Currently I'm using: Public Const Doc_01 As String = "Rules.DOC" Public Const Doc_02 As String = "Personal.DOC" Public Const Doc_03 As String = "Reporting.DOC" ....but that doesn't allow me to run through the documents in a loop, like a For-To-Next. Any suggentions? TIA, |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Charlotte,
You could do something like this Sub sonic() Dim WordApp As Object, WordDoc As Object Set WordApp = CreateObject("Word.Application") mypath = "C:\" MyArr = Array("Rules.doc", "Personal.doc", "Reporting.doc") For x = LBound(MyArr) To UBound(MyArr) WordApp.documents.Open mypath & MyArr(x) WordApp.Visible = True 'do things Next End Sub Mike "Charlotte E" wrote: Hello, Is there a way to make Constants as Arrays? Something like: Public Const Doc(1) As String = "Rules.DOC" Public Const Doc(2) As String = "Personal.DOC" Public Const Doc(3) As String = "Reporting.DOC" etc... Currently I'm using: Public Const Doc_01 As String = "Rules.DOC" Public Const Doc_02 As String = "Personal.DOC" Public Const Doc_03 As String = "Reporting.DOC" ....but that doesn't allow me to run through the documents in a loop, like a For-To-Next. Any suggentions? TIA, |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc"
Sub test() Dim v For Each v In Split(cDOCS, "\") MsgBox v, , "For Each" Next ' or Dim i As Long, arr arr = Split(cDOCS, "\") For i = 0 To UBound(arr) MsgBox arr(i), , "For i =" Next End Sub Regards, Peter T "Charlotte E" <@ wrote in message ... Hello, Is there a way to make Constants as Arrays? Something like: Public Const Doc(1) As String = "Rules.DOC" Public Const Doc(2) As String = "Personal.DOC" Public Const Doc(3) As String = "Reporting.DOC" etc... Currently I'm using: Public Const Doc_01 As String = "Rules.DOC" Public Const Doc_02 As String = "Personal.DOC" Public Const Doc_03 As String = "Reporting.DOC" ...but that doesn't allow me to run through the documents in a loop, like a For-To-Next. Any suggentions? TIA, |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I might misunderstand the meaning of Charlotte's "To make Constants as
Arrays". But I can change elements of the constant array(arr). I wonder this could be called as a constant array. Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc" Sub test() Dim i As Long, arr arr = Split(cDOCS, "\") For i = 0 To UBound(arr) MsgBox arr(i), , "For i = " & i Next For i = 0 To UBound(arr) arr(i) = Replace(UCase(arr(i)), "R", "A") Next For i = 0 To UBound(arr) MsgBox arr(i), , "After Modifing For i = " & i Next End Sub Keiji Peter T wrote: Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc" Sub test() Dim v For Each v In Split(cDOCS, "\") MsgBox v, , "For Each" Next ' or Dim i As Long, arr arr = Split(cDOCS, "\") For i = 0 To UBound(arr) MsgBox arr(i), , "For i =" Next End Sub Regards, Peter T "Charlotte E" <@ wrote in message ... Hello, Is there a way to make Constants as Arrays? Something like: Public Const Doc(1) As String = "Rules.DOC" Public Const Doc(2) As String = "Personal.DOC" Public Const Doc(3) As String = "Reporting.DOC" etc... Currently I'm using: Public Const Doc_01 As String = "Rules.DOC" Public Const Doc_02 As String = "Personal.DOC" Public Const Doc_03 As String = "Reporting.DOC" ...but that doesn't allow me to run through the documents in a loop, like a For-To-Next. Any suggentions? TIA, |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Constants can only refer to a value, not an array or object. The example I
posted makes a variable array from the constant string using the Split function with the delimiter "\". After making the variable array from the fixed constant you can of course change the array as you wish. Regards, Peter T "keiji kounoike" <"kounoike AT mbh.nifty.com" wrote in message ... I might misunderstand the meaning of Charlotte's "To make Constants as Arrays". But I can change elements of the constant array(arr). I wonder this could be called as a constant array. Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc" Sub test() Dim i As Long, arr arr = Split(cDOCS, "\") For i = 0 To UBound(arr) MsgBox arr(i), , "For i = " & i Next For i = 0 To UBound(arr) arr(i) = Replace(UCase(arr(i)), "R", "A") Next For i = 0 To UBound(arr) MsgBox arr(i), , "After Modifing For i = " & i Next End Sub Keiji Peter T wrote: Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc" Sub test() Dim v For Each v In Split(cDOCS, "\") MsgBox v, , "For Each" Next ' or Dim i As Long, arr arr = Split(cDOCS, "\") For i = 0 To UBound(arr) MsgBox arr(i), , "For i =" Next End Sub Regards, Peter T "Charlotte E" <@ wrote in message ... Hello, Is there a way to make Constants as Arrays? Something like: Public Const Doc(1) As String = "Rules.DOC" Public Const Doc(2) As String = "Personal.DOC" Public Const Doc(3) As String = "Reporting.DOC" etc... Currently I'm using: Public Const Doc_01 As String = "Rules.DOC" Public Const Doc_02 As String = "Personal.DOC" Public Const Doc_03 As String = "Reporting.DOC" ...but that doesn't allow me to run through the documents in a loop, like a For-To-Next. Any suggentions? TIA, |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Oh, yeah...
This is the way to do it - thanks, Peter :-) Peter T wrote: Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc" Sub test() Dim v For Each v In Split(cDOCS, "\") MsgBox v, , "For Each" Next ' or Dim i As Long, arr arr = Split(cDOCS, "\") For i = 0 To UBound(arr) MsgBox arr(i), , "For i =" Next End Sub Regards, Peter T "Charlotte E" <@ wrote in message ... Hello, Is there a way to make Constants as Arrays? Something like: Public Const Doc(1) As String = "Rules.DOC" Public Const Doc(2) As String = "Personal.DOC" Public Const Doc(3) As String = "Reporting.DOC" etc... Currently I'm using: Public Const Doc_01 As String = "Rules.DOC" Public Const Doc_02 As String = "Personal.DOC" Public Const Doc_03 As String = "Reporting.DOC" ...but that doesn't allow me to run through the documents in a loop, like a For-To-Next. Any suggentions? TIA, |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In my thought, if you say a variable is constant, you cannot change it's
value. In some other languages like C, you can make a constant array. In VBA, it seems to be impossible to make a constant array. then, I wonder why the poster needs the constants in this case. I think a code like this would be enough. Dim arr as Variant Sub test() arr = Array("Rules.DOC", "Personal.DOC", "Reporting.DOC") For i = 0 To UBound(arr) MsgBox arr(i), , "For i = " & i Next End Sub Keiji Peter T wrote: Constants can only refer to a value, not an array or object. The example I posted makes a variable array from the constant string using the Split function with the delimiter "\". After making the variable array from the fixed constant you can of course change the array as you wish. Regards, Peter T "keiji kounoike" <"kounoike AT mbh.nifty.com" wrote in message ... I might misunderstand the meaning of Charlotte's "To make Constants as Arrays". But I can change elements of the constant array(arr). I wonder this could be called as a constant array. Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc" Sub test() Dim i As Long, arr arr = Split(cDOCS, "\") For i = 0 To UBound(arr) MsgBox arr(i), , "For i = " & i Next For i = 0 To UBound(arr) arr(i) = Replace(UCase(arr(i)), "R", "A") Next For i = 0 To UBound(arr) MsgBox arr(i), , "After Modifing For i = " & i Next End Sub Keiji Peter T wrote: Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc" Sub test() Dim v For Each v In Split(cDOCS, "\") MsgBox v, , "For Each" Next ' or Dim i As Long, arr arr = Split(cDOCS, "\") For i = 0 To UBound(arr) MsgBox arr(i), , "For i =" Next End Sub Regards, Peter T "Charlotte E" <@ wrote in message ... Hello, Is there a way to make Constants as Arrays? Something like: Public Const Doc(1) As String = "Rules.DOC" Public Const Doc(2) As String = "Personal.DOC" Public Const Doc(3) As String = "Reporting.DOC" etc... Currently I'm using: Public Const Doc_01 As String = "Rules.DOC" Public Const Doc_02 As String = "Personal.DOC" Public Const Doc_03 As String = "Reporting.DOC" ...but that doesn't allow me to run through the documents in a loop, like a For-To-Next. Any suggentions? TIA, |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Wierd names defined as arrays of constants?!? | Excel Discussion (Misc queries) | |||
Wierd names defined as arrays of constants?!? | Excel Discussion (Misc queries) | |||
Trouble with arrays (transferring values between two arrays) | Excel Programming | |||
Working with ranges in arrays... or an introduction to arrays | Excel Programming | |||
Arrays - declaration, adding values to arrays and calculation | Excel Programming |