Jump to content

Add & remove bookmark from MS Word


ajit
 Share

Recommended Posts

#include <IE.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>

; forum link http://www.autoitscript.com/forum/index.php?showtopic=116346

Global Const $SC_RESTORE = 0xF120;
Global $Redraw_flag

_IEErrorHandlerRegister ()
$oIE = _IECreateEmbedded()
$hGUI = GUICreate("Embedded word control Test", 940, 680, (@DesktopWidth - 940) / 2, (@DesktopHeight - 680) / 2, _
       $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 900, 460)
$button_1 = GUICtrlCreateButton("Minimize, then Restore", 180, 580, 150, 25)
$button_2 = GUICtrlCreateButton("Add Bookmark", 350, 580, 100, 25)
$button_3 = GUICtrlCreateButton("Select Bookmark", 460, 580, 100, 25)
$button_4 = GUICtrlCreateButton("Remove Bookmark", 570, 580, 100, 25)
 GUISetState()


    $sFile = @DesktopDir & "\test.Doc"
    _IENavigate ($oIE, $sFile, 0)
    While $oIE.ReadyState <> 4
        Sleep(50)
    WEnd

    $oDoc = $oIE.Document
    $oWord = $oDoc.Application
    ; Put document into 'Web View' mode
    $oWord.Activewindow.View = 4; 6
    ; Manage display of toolbars
    $oDoc.CommandBars ("Reviewing").Visible = False
    $oDoc.CommandBars ("Standard").Visible = True
    $oDoc.CommandBars("Formatting").Visible = True
;   $oDoc.CommandBars("Formatting").Visible = False
;   $oDoc.CommandBars("Drawing").Visible = False
;   $oDoc.CommandBars("Forms").Visible = False
 ; $oDoc.DisplayStatusBar = True
;   $oDoc.DisplayCommentIndicator = 0
    GUIRegisterMsg($WM_ACTIVATE,"WM_ACTIVATE")


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $button_1
            GUISetState(@SW_MINIMIZE)
            Sleep(300)
            GUISetState(@SW_RESTORE)
        Case $button_2 ; Add Bookmar at insertion point


        Case $button_3 ; Select bookmark (not sure)


        Case $button_4 ; Remove bookkark


        Case $GUI_EVENT_CLOSE
            ExitLoop
        CAse $GUI_EVENT_RESTORE, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED
            $Redraw_flag = 1
    EndSwitch

        If $Redraw_flag Then
        GUISetState(@SW_LOCK)
        GUISetStyle(-1, $WS_EX_COMPOSITED, $hGUI)
        GUISetStyle(-1, 0, $hGUI)
        $Redraw_flag = 0
        GUISetState(@SW_UNLOCK)
        EndIf
        Sleep(10)
WEnd

_IENavigate ($oIE, "about:blank")
$oDoc = 0
$oWord = 0
GUIDelete()
Exit

Func WM_ACTIVATE($hWndGUI, $MsgID, $wParam, $lParam)
    If $wParam = 1 Then
        $Redraw_flag = 1
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Hi:

I have borrowed this code from the forum.

Link: http://www.autoitscript.com/forum/index.php?showtopic=116346

A word document "test.doc" is required on desktop

It almost works fine, except that sometimes the object is not redrawn properly but that is okay since that is the best code I found on the forum embedding MS Word.

Could someone show me how to add and remove bookmarks? MSDN literature is too tough for me without a programming background.

Thanking in anticipation

Regards

Ajit

Edited by ajit
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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