Sunday, December 06, 2009

check if Bookmark or Name is exists in Word/Excel application

I did not have tasks with export data from LN to word/excel/pdf for 1 years probably. My today's task was easy, I had to export data from LN to xml, processed it using xsl, walk through resulting xml and export everything to word/excel. Then I had to copy values from resulting xml to word/excel's temlpate using bookmarks (in excel it is names).

Here is an example how to check bookrmark/names in word/excel (because before I did not have experience with Excel's names)

excel approach I got from this link

Function NameExists(TheName
as String, obj, formType as String) As Boolean

NameExists = False

Select Case formType
Case "word":
if obj.activedocument.Bookmarks.Exists(TheName) Then
NameExists = true
End If
Case "excel"
On Error Resume Next
NameExists = Len(obj.names(TheName).Name) <> 0
End Select

End Function

No comments :