Jump to content

Is it possible to use "_Word_DocRangeSet" function in vb.net ?


Recommended Posts

Hi all,

I need to use an autoit function named "_Word_DocRangeSet" in vb.net. Is it possible. I do know about the AutoItServer.au3 file by AutoItObject Team. So i am searching for another methods. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

You could simply translate it to VB. 

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

 

Link to comment
Share on other sites

Um, that's not a bad idea, but need more study. I didn't find a correct option to move the range backward from cursor point in vb.net. Anyway, let me study the function deeply. Thanks @water 

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Moving the cursor etc. is Word COM stuff. So it should be possible to convert it to VB. What you need to change is the AutoIt stuff to VB.

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

 

Link to comment
Share on other sites

@water , Thank you for the inspiration. I have successfuly translated the function into vb.net. But i have one doubt. Assume that i am going to get 3 words backward from cursor. So i gave parameters like this. (OWordObject, 0, 2, -3). Assume that the text in my word document is like this "He is... " 

You see, two english words and 3 dots and white space. But my function is returning only the dots. I don't know it includes white space. But i need to get only the two english words from this context. How ?

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Have you tried this with _Word_DocRangeSet? Does it return the same result?

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

 

Link to comment
Share on other sites

@water , _Word_DocRangeSet is giving correct result. No problem. I think my translated function is the problem. Here it is.

Public Function Word_DocRangeSet( _
ByVal oDoc As Object, _
ByVal vRange As Object, _
Optional ByVal iStartUnit As Object = 0, _
Optional ByVal iStartCount As Object = 1, _
Optional ByVal iEndUnit As Object = 0, _
Optional ByVal iEndCount As Object = 1) As Object
       
        If iStartUnit = 0 Then iStartUnit = Word.WdUnits.wdWord
        If iEndUnit = 0 Then iEndUnit = Word.WdUnits.wdWord
       
        If vRange = -1 Then
            vRange = oDoc.Range 
           vRange.Collapse(Word.WdCollapseDirection.wdCollapseStart)
        ElseIf vRange = -2 Then
            vRange = oDoc.Range 
           vRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
        ElseIf vRange = 0 Then
            vRange = oDoc.Parent.Selection.Range 
       End If
        Try
            If iStartUnit = -1 Then
                vRange.Collapse(Word.WdCollapseDirection.wdCollapseStart)
 
            ElseIf iStartCount <> 1 Then
                vRange.MoveStart(iStartUnit, iStartCount)
 
            End If
            If iEndUnit = -1 Then
                vRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
 
            ElseIf iEndCount <> 0 Then
                vRange.MoveEnd(iEndUnit, iEndCount)
 
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return vRange
    End Function

For testing purpose, i didn't put any error finding tests in this function. 

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Just had a quick look at your code (without testing). I would use 0 for all optional values to be the "Default" value.

Public Function Word_DocRangeSet(ByVal oDoc As Object, ByVal vRange As Object, Optional ByVal iStartUnit As Object = 0, Optional ByVal iStartCount As Object = 0, Optional ByVal iEndUnit As Object = 0, Optional ByVal iEndCount As Object = 0)
           
            If iStartUnit = 0 Then iStartUnit = Word.WdUnits.wdWord
            If iEndUnit = 0 Then iEndUnit = Word.WdUnits.wdWord
            If vRange = -1 Then
                vRange = oDoc.Range ' Set range start/end at the start to the document
               vRange.Collapse(Word.WdCollapseDirection.wdCollapseStart)
            ElseIf vRange = -2 Then
                vRange = oDoc.Range ' Set range start/end at the end to the document
               vRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
            ElseIf vRange = 0 Then
                vRange = oDoc.Parent.Selection.Range ' Use the current selection as range
           End If
            Try
                If iStartUnit = -1 Then
                    vRange.Collapse(Word.WdCollapseDirection.wdCollapseStart)
                ElseIf iStartCount <> 0 Then
                    vRange.MoveStart(iStartUnit, iStartCount)
                End If
                If iEndUnit = -1 Then
                    vRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
                ElseIf iEndCount <> 0 Then
                    vRange.MoveEnd(iEndUnit, iEndCount)
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            Return vRange
        End Function

 

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

 

Link to comment
Share on other sites

I have used 1 as default value because, msdn says startCount and endCount values are 1. 

But my main problem is, how can i run this program when my form1 is not in focus . I have tested BackGroundWorker class, but didn't get the intended result. Thinking about using timer's tick event. 

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

But in this function 0 is more sensible because with 1 you would always move the start AND end of the range even if you just wanted to move one of them.

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

 

Link to comment
Share on other sites

Ok, let me correct it. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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

×
×
  • Create New...