Consulting

Results 1 to 5 of 5

Thread: Paste to navigation search box from userform

  1. #1
    VBAX Regular
    Joined
    Mar 2020
    Posts
    79
    Location

    Paste to navigation search box from userform

    I am using a form in a VBA macro in Word.

    In Word 2010 there is a navigation pane.
    At the top you can type something to search.

    I want to paste data I have in the clipboard to that navigation pane search box.
    I can't seem to activate that navigation search box with what I have tried.

    So my form lists out the result of a regex search into a textbox. I triple click to select the line I want to now locate in the Word document and press a button on my form.
    The msgbox shows with the correct data, so that is good so far.
    It is just the next step that I need. (I have commented out the SendKeys part). How to select that search box and then I can use the SendKeys part of the code.

    Private Sub CommandButton48CopyTextInTextbox_Click()
    TextBox8refList.SetFocus
    TextBox8refList.Copy
    
     Dim DataObj As MSForms.DataObject
     Set DataObj = New MSForms.DataObject
     DataObj.GetFromClipboard
    
    strPaste = DataObj.GetText(1)
    ActiveWindow.DocumentMap = True
    ActiveWindow.SetFocus
    
    
    ActiveDocument.Activate
    'SendKeys "^(f){backspace}^{v}{Enter}"
    MsgBox (strPaste)
    End Sub
    thanks in advance for any assistance.
    Jon

  2. #2
    VBAX Regular
    Joined
    Mar 2020
    Posts
    79
    Location
    Private Sub CommandButton48CopyTextInTextbox_Click()
    
    If selection.Type = wdSelectionIP Then InSelection = True
    
    
    selection.HomeKey wdStory
    TextBox8refList.SetFocus
    
    
    SendKeys "{Home}"
    SendKeys "+{End}"
    DoEvents 'This was the key to this working. Macro was going ahead of itself
    TextBox8refList.SetFocus
    
    
    TextBox8refList.Copy
    
    
     Dim DataObj As MSForms.DataObject
     Set DataObj = New MSForms.DataObject
     DataObj.GetFromClipboard
    
    
    strPaste = DataObj.GetText(1)
    
    
    Dim dlg As Dialog
    Set dlg = Application.Dialogs(wdDialogEditFind)
    dlg.Find = strPaste
    SendKeys "%(f){tab}{ENTER}"
    dlg.Show
    
    ''''''This section added, and it makes it use the navigation window
    If CheckBox17NavigationPane.Value = True Then
        SendKeys "^f"
        SendKeys "^v"
        SendKeys "{ENTER}"
    End If
    
    
    ''''''''''''''''''''''''''''''''''''''
    End Sub
    Well after much trial and error I found this works and with the checkbox option I can have it use either the regular search box or the navigation pane.

  3. #3
    VBAX Regular
    Joined
    Mar 2020
    Posts
    79
    Location
    I was having some issues and could not figure it. This seems to have fixed things. If there are any improvements please say. This is all a bit new territory for me.


    Private Sub CommandButton48CopyTextInTextbox_Click()On Error Resume Next
    If selection.Type = wdSelectionIP Then InSelection = True
    selection.Find.MatchWildcards = False 'don't forget to set this
    
    
    selection.HomeKey wdStory
    TextBox8refList.SetFocus
    
    
    SendKeys "{Home}"
    SendKeys "+{End}"
    DoEvents    'This was the key to this working. Macro was going ahead of itself
    TextBox8refList.SetFocus
    CloseClipboard 'hmm looks like this was another key part
    DoEvents
    TextBox8refList.Copy
    
    
    Dim DataObj    As MSForms.DataObject
    Set DataObj = New MSForms.DataObject
    DataObj.GetFromClipboard
    'DoEvents
    strPaste = DataObj.GetText(1)
    'DoEvents
    
    
    Dim dlg        As Dialog
    Set dlg = Application.Dialogs(wdDialogEditFind)
    dlg.Find = strPaste
    SendKeys "%(f){tab}{ENTER}"
    'dlg.Show
    ''''''This section added, and it makes it use the navigation window
    'On Error Resume Next
    'ActiveWindow.SetFocus
    'DoEvents
    If CheckBox17NavigationPane.Value = True Then
        SendKeys "^f"
        SendKeys "^v"
        SendKeys "{ENTER}"
    End If
    
    
    ''''''''''''''''''''''''''''''''''''''
    
    
    
    
    
    
    End Sub

  4. #4
    VBAX Regular
    Joined
    Mar 2020
    Posts
    79
    Location
    This is odd. The above does not work now since I restarted Word.....
    Time for a rethink I suppose. I guess I have missed resetting something... but what?

  5. #5
    VBAX Regular
    Joined
    Mar 2020
    Posts
    79
    Location
    Rolled back to this and it works.

    Private Sub CommandButton48CopyTextInTextbox_Click()
    
    
    If selection.Type = wdSelectionIP Then InSelection = True
    
    
    selection.HomeKey wdStory
    TextBox8refList.SetFocus
    
    
    SendKeys "{Home}"
    SendKeys "+{End}"
    DoEvents    'This was the key to this working. Macro was going ahead of itself
    TextBox8refList.SetFocus
    
    
    TextBox8refList.Copy
    
    
    Dim DataObj    As MSForms.DataObject
    Set DataObj = New MSForms.DataObject
    DataObj.GetFromClipboard
    
    
    strPaste = DataObj.GetText(1)
    
    
    Dim dlg        As Dialog
    Set dlg = Application.Dialogs(wdDialogEditFind)
    dlg.Find = strPaste
    SendKeys "%(f){tab}{ENTER}"
    dlg.Show
    ''''''This section added, and it makes it use the navigation window
    'On Error Resume Next
    'ActiveWindow.SetFocus
    'DoEvents
    If CheckBox17NavigationPane.Value = True Then
        SendKeys "^f"
        SendKeys "^v"
        SendKeys "{ENTER}"
    End If
    
    
    ''''''''''''''''''''''''''''''''''''''
    
    
    
    
    
    
    End Sub

Tags for this Thread

Posting Permissions

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