Jump to content

Recommended Posts

Posted

Hi There

I need to write a UDF which fills a bookmark in a word file with a value and then recreates the bookmark (because it gets deleted after the filling).

The original VBA code found on the internet is:

Set rngAdresse = ActiveDocument.Bookmarks!TM_Test

rngAdresse.Text = "Test value"

ActiveDocument.Bookmarks.Add "TM_Test", rngAdresse

but i don't know how to write this in AutoIT. Here is what i have so far:

Func _WordLib_BookmarkFill(ByRef $oWordDoc,$sBookmarkName,$sBookmarkText)
    _Log("_WordLib_BookmarkExist():" & @ScriptLineNumber,"1",$LOG_ERROR)
    Local $vRangeBookmark=$oWordDoc.Bookmarks & "!" & $sBookmarkName

    _Log("_WordLib_BookmarkExist():" & @ScriptLineNumber,"2",$LOG_ERROR)
    $vRangeBookmark.Text=$sBookmarkText

    _Log("_WordLib_BookmarkExist():" & @ScriptLineNumber,"3",$LOG_ERROR)
    $oWordDoc.Bookmarks.Add('"' & $sBookmarkName & '"',$vRangeBookmark)

    _Log("_WordLib_BookmarkExist():" & @ScriptLineNumber,"4",$LOG_ERROR)
    Return 1
EndFunc

Once running, the text is not inserted and i get the following in my log (a function named errfunc() is used to capture the COM errors)

[03/02/2015 15:56:59] [ VM-TOMMY ] errfunc():1642: a COM error has occured in line 53, number is: 80020006 Description is: Unbekannter Name.
[03/02/2015 15:57:00] [ VM-TOMMY ] _WordLib_BookmarkExist():73: 1
[03/02/2015 15:57:00] [ VM-TOMMY ] _WordLib_BookmarkExist():75: 2
[03/02/2015 15:57:00] [ VM-TOMMY ] errfunc():1642: a COM error has occured in line 76, number is: 80020006 Description is: Unbekannter Name.
[03/02/2015 15:57:00] [ VM-TOMMY ] _WordLib_BookmarkExist():77: 3
[03/02/2015 15:57:00] [ VM-TOMMY ] errfunc():1642: a COM error has occured in line 78, number is: 80020009 Description is: Ausnahmefehler aufgetreten.
[03/02/2015 15:57:00] [ VM-TOMMY ] _WordLib_BookmarkExist():79: 4

Can somebody help me on how to format that AutoIT code properly? :(

Cheers

Thomy

Posted

In VBA "!" stands for the default property of an object. Seems to be the Item property for the Bookmarks object.

So it should be:

Func _WordLib_BookmarkFill(ByRef $oWordDoc,$sBookmarkName,$sBookmarkText)
     _Log("_WordLib_BookmarkExist():" & @ScriptLineNumber,"1",$LOG_ERROR)
     Local $vRangeBookmark=$oWordDoc.Bookmarks.Item($sBookmarkName)
     _Log("_WordLib_BookmarkExist():" & @ScriptLineNumber,"2",$LOG_ERROR)
     $vRangeBookmark.Text=$sBookmarkText
     _Log("_WordLib_BookmarkExist():" & @ScriptLineNumber,"3",$LOG_ERROR)
     $oWordDoc.Bookmarks.Add('"' & $sBookmarkName & '"',$vRangeBookmark)
     _Log("_WordLib_BookmarkExist():" & @ScriptLineNumber,"4",$LOG_ERROR)
     Return 1 
EndFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...