Array already dimensioned vba ошибка

For certain, technical, reasons, we cannot use styles in word. In an effort to speed up applying global properties over and over, I’ve created a class that can read from a simple xml style-sheet. The sheet contains different «paragraphs.» Each paragraph simply stores the paragraph properties that we use the most.

I’m used to C++ where I can use dynamic memory and I’m trying to replicate the behavior of a dynamically allocated array. However, when I attempt to re-dim I get the error message «Array arleady dimensioned.»

My research on the MSDN suggests that in order to ReDim the array has to be Global or in the «general declaration context» This makes me think it might simply not be possible to do it in a class.

Excerpt from MSDN:

«You can use ReDim only at procedure level. Therefore, the declaration
context for the variable must be a procedure; it can’t be a source
file, a namespace, an interface, a class, a structure, a module, or a
block.»

I have attempted to search stack overflow for «Word VBA Array already dimensioned» and went through all 3 pages of results with no avail.

private type pStyle 'Definition removed because it's not needed
private Paragraphs(0) As pStyle 'Initially an empty array of paragraphs

later I have the following function

Public Function AddEmpty()

'Create space
count = count + 1
ReDim Preserve Paragraphs(count)
AddEmpty = count
End Function

Please let me know if any ideas. I would prefer to not have to «estimate» the number of paragraph styles we will need for each style sheet as every file is different.

For certain, technical, reasons, we cannot use styles in word. In an effort to speed up applying global properties over and over, I’ve created a class that can read from a simple xml style-sheet. The sheet contains different «paragraphs.» Each paragraph simply stores the paragraph properties that we use the most.

I’m used to C++ where I can use dynamic memory and I’m trying to replicate the behavior of a dynamically allocated array. However, when I attempt to re-dim I get the error message «Array arleady dimensioned.»

My research on the MSDN suggests that in order to ReDim the array has to be Global or in the «general declaration context» This makes me think it might simply not be possible to do it in a class.

Excerpt from MSDN:

«You can use ReDim only at procedure level. Therefore, the declaration
context for the variable must be a procedure; it can’t be a source
file, a namespace, an interface, a class, a structure, a module, or a
block.»

I have attempted to search stack overflow for «Word VBA Array already dimensioned» and went through all 3 pages of results with no avail.

private type pStyle 'Definition removed because it's not needed
private Paragraphs(0) As pStyle 'Initially an empty array of paragraphs

later I have the following function

Public Function AddEmpty()

'Create space
count = count + 1
ReDim Preserve Paragraphs(count)
AddEmpty = count
End Function

Please let me know if any ideas. I would prefer to not have to «estimate» the number of paragraph styles we will need for each style sheet as every file is different.

Search code, repositories, users, issues, pull requests…

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

curious K

New Member

Joined
Dec 28, 2015
Messages
22


  • #1

Dim GrpTot(1, 2)
‘Col 1 : Amt
‘Col 2 : row no for Where to put
‘col 3 : Column no for where to put

GrpTot(0, 0) = 4896.00
GrpTot(0, 1) = 5
GrpTot(0, 2) = 2

Sheets(«Summary»).Cells(GrpTot(0, 2), GrpTot(0, 1)) = GrpTot(0, 0)

ReDim Preserve GrpTot(2 To 2)

GrpTot(0, 0) = 12541.00
GrpTot(0, 1) = 5
GrpTot(0, 2) = 18

Sheets(«Summary»).Cells(GrpTot(0, 2), GrpTot(0, 1)) = GrpTot(0, 0)

Error occured at ReDim syntax
—————————
Microsoft Visual Basic for Applications
—————————
Compile error:

Array already dimensioned
—————————
OK Help
—————————

Excel Facts

Lock one reference in a formula

Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Kyle123

Kyle123

Well-known Member

Joined
Jan 24, 2012
Messages
2,769


  • #2

To define a dynamic array, don’t Dim it with a size:

Rich (BB code):

Dim GrpTot() As Variant
ReDim GrpTot(1,2)

You can’t redim preserve the first dimension of an array, only the last

curious K

New Member

Joined
Dec 28, 2015
Messages
22


  • #3

Sorry I’m new for excel vba world.

Its solved with above code

Thanks :)

Понравилась статья? Поделить с друзьями:
  • Armxxl 105 коды ошибок
  • Arnavi 4 статус дд ошибка
  • Armxxl 1297 коды ошибок
  • Armxxd 1097 ошибка f13
  • Ariston bs ii 15ff код ошибки