+ Reply to Thread
Results 1 to 5 of 5

Making Range Selection from Word in Excel VBA

  1. #1
    Registered User
    Join Date
    10-04-2018
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2013
    Posts
    6

    Question Making Range Selection from Word in Excel VBA

    Hey guys, I am trying to figure out problem with VBA and Word. I need to select range from word document, currently I have working Word VBA script, but trying to implement it in Excel does not work like it should in my mind. It is making selection from already open word document.
    Word Script:
    Dim SelectedRange As Range
    Set SelectedRange = ActiveDocument.Range

    With SelectedRange.Find
    .Execute FindText:="number 51"
    End With

    MsgBox "Position=" & SelectedRange.Start
    a = SelectedRange.Start + 11
    b = a + 440

    Set rngParagraphs = ActiveDocument.Range(Start:=a, End:=b)
    rngParagraphs.Select
    Excel Script:
    Dim msWord As Object
    Dim SelectedRange As Object
    Dim rngParagraphs As Object
    Dim strName As String
    Set msWord = GetObject(, "Word.Application")
    Set msWordActive = msWord.ActiveDocument.Content
    Dim boxString As String
    boxString = TextBox1.Value
    i = Right(boxString, 1)
    strName = "number " + i

    With msWordActive.Find
    .Execute FindText:=strName
    End With

    Set SelectedRange = msWordActive.Paragraphs(1).Range
    MsgBox "Position=" & SelectedRange.Start
    a = SelectedRange.Start + 40
    b = a + 440
    MsgBox msWordActive.Paragraphs.Count
    Set rngParagraphs = msWordActive.Paragraphs(1).Range(Start:=a, End:=b)
    rngParagraphs.Select
    Excel script is making Named argument not found error.
    Last edited by kristers77; 12-14-2018 at 04:32 PM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Making Range Selection from Word in Excel VBA

    you can not used named arguments when late binding.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    10-04-2018
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2013
    Posts
    6
    Quote Originally Posted by Andy Pope View Post
    you can not used named arguments when late binding.
    What would be the alternative to fix the problem? It does work without Range arguments, that's correct. It only selects one Paragraphs sentence.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Making Range Selection from Word in Excel VBA

    I did not say remove the arguments, only that they can not be named as you are not using the library the compiler can not deal with them.

    Please Login or Register  to view this content.
    Also you excel version of the code explicit references Paragraph where as the word version is activedocument.

  5. #5
    Registered User
    Join Date
    10-04-2018
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Making Range Selection from Word in Excel VBA

    Quote Originally Posted by Andy Pope View Post
    I did not say remove the arguments, only that they can not be named as you are not using the library the compiler can not deal with them.

    Please Login or Register  to view this content.
    Also you excel version of the code explicit references Paragraph where as the word version is activedocument.
    Thanks, it did fix the issue playing around with ActiveDocument.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy Excel range a number of sheets as pictures to MS Word, each picture on new Word page.
    By IGTsmith in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2018, 09:23 AM
  2. Making Word MailMerge work from within Excel;
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2016, 12:27 PM
  3. Replies: 7
    Last Post: 09-11-2014, 12:47 PM
  4. [SOLVED] Cannot get word Selection object from within Excel macro
    By MattyChan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2012, 06:25 PM
  5. Creating selection inside word table from excel vba
    By Alexander_Golinsky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2012, 01:34 AM
  6. Excel/Word selection formatting issues
    By rivvorz in forum Excel General
    Replies: 0
    Last Post: 01-29-2007, 07:30 AM
  7. [SOLVED] Making Excel's open command work like Word
    By 280Z28 in forum Excel General
    Replies: 2
    Last Post: 06-08-2006, 12:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1