WORD VBA program, can only process 50 documents at a time.

B

bobk544

Hello,

In "pgmcntl()" - 1of2 macros below, i can only process 50 WORD documents at
a time, or the HYPERLINK settings start getting the following error message:

Error! Hyperlink reference not valid.

I think all of the documents are being stored in memory and not actually
being released even though I have this statement in the 2nd macro called
“pgmlink()â€:

ActiveDocument.Save '(wdSaveChanges)
ActiveDocument.Close

I'm currently trying to process 211 documentsl, but this will increase to 400+

Thanks any help on this and thanks for the help on previous posts! can't
find out where to rate previous posts though!
BobK

-------------------------------------------------------------------------------------------------------------------------------------

Sub pgmcntl()

Dim FileArray() As String, ffile As String, Count As Integer
Count = 0

With Dialogs(wdDialogFileOpen)
.Name = "*.*"
.Show
End With

ffile = Dir("*")

ReDim FileArray(Count) ' 0 based array -- dimensioning for 1 entry in
the array
FileArray(Count) = LCase(ffile)
Count = 1
Do While ffile <> ""
ffile = Dir()
'MsgBox ("ffile2" + ffile)
If ffile <> "." And ffile <> ". ." Then
ReDim Preserve FileArray(Count) ' Resizing array dynamically
FileArray(Count) = LCase(ffile)
Count = Count + 1
End If
Loop

Dim lb As Integer
Dim ub As Integer
lb = LBound(FileArray(), 1)
ub = UBound(FileArray(), 1)
ub = ub - 1

Dim f As String

For i = 0 To 49

'For i = 50 To 99
'For i = 100 To 149
'For i = 150 To 199
'For i = 200 To 249
'For i = 250 To 299
'For i = 300 To 349

f = FileArray(i)
Documents.Open (f)

pgmlink

Next

End Sub

----------------------------------------------------------------------------------------------------------------------------

Sub pgmlink()
'These hold the range of the words we are looking at
Dim aword As Range 'The current word range
Dim pword As Range 'The previous word range
Dim sw As String 'Raw word pulled from doc
Dim Excludes As String 'Words to be excluded
Dim SingleWord As String

Dim bm As String
Dim naddr As String
Dim xref As String
Dim rdir As String
Dim line As String
Dim impflag As String
Dim bs1 As Integer
Dim es1 As Integer
Dim bs2 As Integer
Dim es2 As Integer

Dim la(100) As String

Dim ar(10) As String
Dim i As Integer
ar(9) = ""
ar(8) = ""
ar(7) = ""
ar(6) = ""
ar(5) = ""
ar(4) = ""
ar(3) = ""
ar(2) = ""
ar(1) = ""
ar(0) = ""

Set pword = Nothing

For Each aword In ActiveDocument.Words

sw = Trim(LCase(aword))

If sw <> vbCr And sw <> vbLf And sw <> vbCrLf Then
ar(9) = ar(8)
ar(8) = ar(7)
ar(7) = ar(6)
ar(6) = ar(5)
ar(5) = ar(4)
ar(4) = ar(3)
ar(3) = ar(2)
ar(2) = ar(1)
ar(1) = ar(0)
ar(0) = sw
End If

If ar(1) = "@" And ar(0) = "b" Then
xref = "y"
End If

If xref = "y" Then

Dim ls As Long
ls = Len(sw)

Dim pc As Integer
pc = InStr(1, sw, "x", Compare)
If pc = 0 Then
pc = InStr(1, sw, "n", Compare)
End If
If pc = 0 Then
pc = InStr(1, sw, "c", Compare)
End If
If pc = 0 Then
pc = InStr(1, sw, "f", Compare)
End If
If pc = 0 Then
pc = InStr(1, sw, "i", Compare)
End If
If pc = 0 Then
pc = InStr(1, sw, "h", Compare)
End If


bs1 = 0
es1 = pc
bs2 = es1 + 1
es2 = ls

Dim s1 As String
s1 = " "
Dim d1 As Integer
d1 = es1 - bs1 - 1

If pc <> 0 Then

'MsgBox ("1." + sw + " pc: " + CStr(pc))

s1 = Mid$(sw, 1, d1)

ls = Len(s1)

If ls = 1 Then
s1 = "00" + s1
End If

If ls = 2 Then
s1 = "0" + s1
End If

rdir = "c:\_XREF_PGMS\n" + s1 + "*"

'MsgBox ("2." + rdir)
sdir = Dir(rdir)
sdir = "c:\_XREF_PGMS\" + sdir

'MsgBox ("3." + aword + " " + sdir)

s1 = Mid$(sw, pc + 1, es2)

'MsgBox (s1)

Dim sa As String
sa = "b" + s1

'MsgBox ("4." + sa)

With ActiveDocument.Hyperlinks
.Add Anchor:=aword, _
Address:=sdir, SubAddress:=sa
End With

End If

End If

If ar(1) = "@" And ar(0) = "e" Then
xref = "n"
End If

If sw <> vbCr And sw <> vbLf And sw <> vbCrLf Then
Set pword = aword
End If

If sw = vbCr Or sw = vbLf Or sw = vbCrLf Then
impflag = "n"
End If

Next aword


Set aword = Nothing
Set pword = Nothing

ActiveDocument.Save '(wdSaveChanges)
ActiveDocument.Close

End Sub



Here’s where the HYPERLINKs are working:

<%xref_hier%> <%xref_pgmref%> <%xref_allref%> <%xref_sysout%>
<%xref_notes%> <%srch_text%> <%srch_copy%> <%srch_run%>

| fut_opt | date | liab_choice | GSE_CT_LIB | GSE_data | Bond_cashflow |

0 ////////////////////////////////////////////////////////////////
1 //
2 // Filename : fut_opt.h @b <1> 100c38 135f48 135f54 <2>
<3> @e
3 //
4 // Description : @b <1> @e
5 //
6 // 100 Header file for the fut_opt class. @b <1> <2> <3> <4>
100c38 135f48 135f54 <5> <6> @e
7 //
8 //
9 // Classes : @b <1> @e
10 //
11 // fut_opt - The main driver for processing Futures data.
@b 100c38 135f48 135f54 <1> <2> <3> <4> <5> <6> <7> <8> @e
12 // Provides methods used exclusively for @b
<1> <2> <3> <4> <5> @e
13 // generating Futures-related cashflows. @b
<1> <2> <3> <4> @e
14 //
15 //
16 // Contact : (e-mail address removed) (email) @b <1> <2>
<3> <4> <5> @e
17 //
18 ////////////////////////////////////////////////////////////////
19 100
20 #ifndef _FUT_OPT_ @b <1> <2> @e
21 #define _FUT_OPT_ @b <1> <2> @e
22 100
23 #include <stdio.h> @b <1> <2> <3> @e
24 #include <math.h> @b <1> <2> <3> @e
25 #include <ctype.h> @b <1> <2> <3> @e
26 #include "lia_enum.h" @b <1> <2> <3> @e
27 #include "date.h" @b <1> 89c30 126f34 126f38 <2> <3> @e
28 #include "gse_data##gse.h" @b <1> 102c238 138f30 138f37 <2>
100i35 119i28 83i35 87i38 91i32 <3><4> @e
29 #include"gsectlib.h" @b <1> <2> <3> @e
30 #include "fut_opt_utl.h" @b <1> <2> <3> @e
31 #include "liab_choice.h" @b <1> 113c37 145f230 145f59 <2> <3>
@e
32 100
33 extern liab_choice *liab_choice##e_choice; @b <1> 113c37
145f230 145f59 <2> 113c37 145f230 145f59 <3> 100i33 119i29 83i33 87i36 91i30
<4> @e
34 extern GSE_CT_LIB *gse_ct_lib##read_data; @b <1> 107c34
140f49 140f55 <2> 107c34 140f49 140f55 <3> 100i34 83i34 87i37 91i31 99i33 <4>
@e
35 extern GSE_data *gse_data##gse; @b <1> 102c238 138f30
138f37 <2> 102c238 138f30 138f37 <3> 100i35 119i28 83i35 87i38 91i32 <4> @e
36 extern double * *##index_val; @b <1> <2> <3> 100i36 83i36
87i39 <4> @e
37 100
38 class fut_opt @b <1> 100c38 135f48 135f54 <2> @e
39 {
40 protected: @b <1> @e
41 100 Bond_cashflow *bond_cashflow##option_futures_flow; @b
84c97 120f25 120f30 130f81 133f1074 133f1279 133 <1> 84c97 120f25 120f30
130f81 133f1074 133f1279 133 <2> 100i41 <3> @e
42 100 Bond_cashflow *bond_cashflow##option_futures_premium_flow;
@b 84c97 120f25 120f30 130f81 133f1074 133f1279 133 <1> 84c97 120f25 120f30
130f81 133f1074 133f1279 133 <2> 100i42 <3> @e
43 100 *##Option_futures **##option_futures; @b <1> 100i43
<2><3> 100i43 <4> @e
44 100 void clear_array(); @b <1> 121f63 122f237 135f65 <2> @e
45 100 void initial(); @b <1> 135f60 <2> @e
46 100 double **##index_val; @b <1> <2> 100i36 83i36 87i39 <3> @e
47 public: @b <1> @e
48 100 fut_opt(); @b 100c38 135f48 135f54 <1> @e
49 100 ~fut_opt(); @b 100c38 135f48 135f54 <1> @e
50 100 void fut_opt_cashflow(*##Option_futures *, Bond_cashflow *,
Bond_cashflow *); @b <1> 135f107 <2> <3> 100i43 <4>84c97


Here’s where the HYPERLINKs are erroring out:


<%xref_hier%> <%xref_pgmref%> <%xref_allref%> <%xref_sysout%>
<%xref_notes%> <%srch_text%> <%srch_copy%> <%srch_run%>

| wlcfgls | wlcfDP |

0 #ifndef _WLCFGLS_H_ @b <1> <2> @e
1 #define _WLCFGLS_H_ @b <1> <2> @e
2 178
3
///////////////////////////////////////////////////////////////////////////////
4 //
5 // Filename : wlcfGLS.h @b <1> Error! Hyperlink reference
not valid. Error! Hyperlink reference not valid. Error! Hyperlink reference
not valid. <2> <3> @e
6 //
7 // Description : @b <1> @e
8 //
9 // 178 This is the header file for the Gross Loss Severity of Single
Family and @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11> <12>
<13> <14> @e
10 // Multifamily. The Loss Severity calculation adds the discount
present @b <1> <2> <3> <4> <5> <6> <7> <8> <9> @e
11 // value of various costs and offsetting revenues associated with
the @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> @e
12 // foreclosure of single family and multifamily properties,
expressed @b <1> <2> <3> <4> <5> <6> <7> <8> @e
13 // as a fraction of Defaulted UPB. @b <1> <2> <3> <4>
<5> <6> @e
14 //
15 //
16 // Classes : @b <1> @e
17 //
18 // This class does two separate calculations for single family and
multifamily @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11> @e
19 // respectively. It needs the input from enterprise data, and output
of previous @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11> <12>
@e
20 // calculations of CMT (single family only), MA, and DP.
@b <1> <2> <3> <4> <5> <6> <7> <8> <9> @e
21 // A. Single Family Gross Loss Severity - there are three steps for
this @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11> <12> @e
22 // calculation: @b <1> @e
23 // 1. Compute REO proceeds in month m (RP) as a fraction of
defaulted UPB. @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11>
<12> <13> <14> @e
24 // 2. Compute MI Claim Amount on loans that defaulted in month m
(CLM) as @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11> <12>
<13> <14> @e
25 // a fraction of defaulted UPB. @b <1> <2> <3> <4>
<5> @e
26 // 3. Compute Gross Loss Severity of loans that defaulted in
month m (GL) as @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11>
<12> <13> <14> @e
27 // a fraction of defaulted UPB. @b <1> <2> <3> <4>
<5> @e
28 // B. Multifamily Gross Loss Severity - there are two steps for this
calculation: @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11>
<12> @e
29 // 1. For convention Loans, compute the Loss Sharing Claim Amount
(CLM) and @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11> <12>
@e
30 // Gross Loss (GL) on loans that defaulted in month m, as a
fraction of @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11> <12>
<13> <14> @e
31 // defaulted UPB. @b <1> <2> @e
32 // 2. For FHA-insured Multifamily Loans, separate Gross Loss
Severity and @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11> @e
33 // Credit Enhancement calculations are not necessary.
@b <1> <2> <3> <4> <5> <6> @e
34 //
35 // All the output from the above calculation is stored and later
passed to the @b <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11>
<12> <13> <14> @e
36 // CE module for Credit Enhancement calculation. @b
Error! Hyperlink reference not valid. Error! Hyperlink reference not valid.
<1><2> <3> <4> <5> <6> @e
37 //
38 // (Please refer to section 3.6.3.6 of RBC Technical Appendix for
complete @b Error! Hyperlink reference not valid. Error!
Hyperlink reference not valid. Error! Hyperlink reference not valid. Error!
Hyperlink reference not valid. <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> <11>
<12> <13> <14> @e
39 // detail discussion of Gross Loss Severity). @b <1>
<2> <3> <4> <5> <6> @e
40 //
41 // Contact : (e-mail address removed) (email) @b <1> <2>
<3> <4> <5> @e
42 //
43
///////////////////////////////////////////////////////////////////////////////
44 #include "wlcfDP.h" @b <1> Error! Hyperlink reference not
valid. Error! Hyperlink reference not valid. Error! Hyperlink reference not
valid. Error! Hyperlink reference not valid. Error! Hyperlink reference not
valid. Error! Hyperlink reference not valid. 198 <2> <3> @e
45 178
46 class wlcfGLS : public wlcfDP @b <1> Error! Hyperlink
reference not valid. Error! Hyperlink reference not valid. Error! Hyperlink
reference not valid. <2> <3> Error! Hyperlink reference not valid. Error!
Hyperlink reference not valid. Error! Hyperlink reference not valid. Error!
Hyperlink reference not valid. Error! Hyperlink reference not valid. Error!
Hyperlink reference not valid. 198 <4> @e
47 {
48 178 public : @b <1> @e
49 178
50 178 wlcfGLS(); @b Error! Hyperlink reference not valid.
Error! Hyperlink reference not valid. Error! Hyperlink reference not valid.
<1> @e
51 178
52 178 void initGLSconst(); @b <1> Error! Hyperlink
reference not valid. <2> @e
53 178
54 178 void initGLS(); @b <1> Error! Hyperlink reference not
valid. Error! Hyperlink reference not valid. Error! Hyperlink reference not
valid. <2> @e
55 178
56 178 void doGLS(const int month); @b <1> Error! Hyperlink
reference not valid. Error! Hyperlink reference not valid. Error! Hyperlink
reference not valid. <2> <3> <4> <5> @e
57 178
58 178 virtual ~wlcfGLS(); @b <1> Error! Hyperlink reference
not valid. Error! Hyperlink reference not valid. Error! Hyperlink reference
not valid. <2> @e
59 178
60 178 protected : @b <1> @e
61 178
62 178 double _gls[1200]; @b <1> <2> <3> @e
63 178 double _clm[1200]; @b <1> <2> <3> @e
64 178 // Singlefamily Only @b <1> <2> @e
65 178 double _rp[1200]; @b <1> <2> <3> @e
66 178
67 178 /* GLS/NLS constants */ @b <1> <2> <3> @e
68 178 double MQ_sold; // Months Delinquent (Sold)
@b <1> <2> <3> <4> <5> @e
69 178 double MQ_retained; // Months Delinquent (Retained)
@b <1> <2> <3> <4> <5> @e
70 178 double RHC; // Net REO holding cost @b
<1> <2> <3> <4> <5> <6> @e
71 178 double mf_MF; // Months from default to completion of
foreclosure @b <1> <2> <3> <4> <5> <6> <7> <8> <9> @e
72 178 double sf_MF; // Months to Forclosure @b
<1> <2> <3> <4> <5> @e
73 178 double mf_MR; // Months from REO acquisition to REO
disposition @b <1> <2> <3> <4> <5> <6> <7> <8> <9> @e
74 178 double sf_MR; // Months in REO @b <1> <2>
<3> <4> <5> @e
75 178 double RP; // REO Proceeds @b <1> <2>
<3> <4> @e
76 178 double F; // Foreclosure Cost @b <1>
<2> <3> <4> @e
77 178 double R; // REO Expenses @b <1> <2>
<3> <4> @e
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Arriving at totals 2
excel copy and paste... 2
Numbers from first column 6
Formating/Macro/Script Help 7
Paragraph numbering in Word 1
relective formula 0
match 3
Find value based on two lookup values 2

Top