By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,646 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,646 IT Pros & Developers. It's quick & easy.

VBA coding - Automating Table and Figure Captions/References

rustaferd
P: 4
I have created VBA code that will automatically generate Table and Figure captions in a Word document, but when I run the code that should automatically generate Table and Figure references, I get a run-time error '4198'.

I need help figuring out why this is occuring and how to fix it. I have the code I would be happy to post if there is anybody out there interested in taking a look and offering suggestions.
Dec 3 '07 #1
Share this Question
Share on Google+
2 Replies


kadghar
Expert 100+
P: 1,295
I have created VBA code that will automatically generate Table and Figure captions in a Word document, but when I run the code that should automatically generate Table and Figure references, I get a run-time error '4198'.

I need help figuring out why this is occuring and how to fix it. I have the code I would be happy to post if there is anybody out there interested in taking a look and offering suggestions.
have you debuged it with F8 to see exactly in what line is your error?
and, yes, i think that it'll be nice if you show us a part of the code.
Dec 3 '07 #2

rustaferd
P: 4
have you debuged it with F8 to see exactly in what line is your error?
and, yes, i think that it'll be nice if you show us a part of the code.
Yes - I did debug with F8 and below shows the place where the error stops:

I can run the Table and figure captions and that works, but when it runs the table or figure references this is the error that pops up…
[IMG]clip_image002.jpg[/IMG]

When I select the Debug button this is what I get…
[IMG]clip_image003.jpg[/IMG]


Here is some of the actual code(I can post more if needed):
[code]Function GetCrossReference(Caption As String, ReferenceType As String) As Integer
Dim refs As Variant
Dim refID As Integer

refs = ActiveDocument.GetCrossReferenceItems(ReferenceTyp e)

For i = 1 To UBound(refs)
If Caption = refs(i) Then refID = i
Next

GetCrossReference = refID

End Function
Sub UpdateCrossReference(curRange As Range, ReferenceType As String)
If (curRange.Style <> "tablecaption") And (curRange.Style <> "figurecaption") And (curRange.Style <> "Caption") Then
'curRange.InsertCrossReference ReferenceType, wdEntireCaption, GetCrossReference(curRange.Text, ReferenceType), True, False, False, " "
Dim iRefID As Integer
iRefID = GetCrossReference(curRange.Text, ReferenceType)
curRange.InsertCrossReference ReferenceType, wdEntireCaption, iRefID, True, False
End If
End Sub[code]
Dec 4 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.