Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2019, 04:29 PM
jeffreybrown jeffreybrown is offline Create bookmark from comma separated text Windows Vista Create bookmark from comma separated text Office 2007
Expert
Create bookmark from comma separated text
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Create bookmark from comma separated text

I have a list of factors in a paragraph separated by a comma. I would like to select the factors and then run a macro to create bookmarks in sequence using an inputbox to ask for the beginning text of the bookmark.

Such as example: In the paragraph, X1, X2, X3, X4, X5, X6. After selecting those six factors, the result would by six bookmarks beginning with the title entered in the inputbox.

CON_1
CON_2
CON_3


CON_4
CON_5
CON_6
Reply With Quote
  #2  
Old 08-15-2019, 04:44 PM
gmaxey gmaxey is offline Create bookmark from comma separated text Windows 10 Create bookmark from comma separated text Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Something like this:


Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim varFactors
Dim lngIndex As Long
Dim strFind As String
Dim oRng As Range
  varFactors = Split(Selection.Text, ",")
  For lngIndex = 0 To UBound(varFactors)
    strFind = InputBox("Enter the string to find.")
    Set oRng = ActiveDocument.Range
    With oRng.Find
      .Text = strFind
      .MatchCase = True
      If .Execute Then
        'If you need to expand the range of the defined text do it here before applying the BM
        oRng.Bookmarks.Add Trim(varFactors(lngIndex)), oRng
      End If
    End With
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-15-2019, 05:08 PM
jeffreybrown jeffreybrown is offline Create bookmark from comma separated text Windows Vista Create bookmark from comma separated text Office 2007
Expert
Create bookmark from comma separated text
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Hi Greg and thank you for the help,

Maybe this isn't quite it so I've attached an example. For the first string, I've created the bookmarks manually and they are CONS1 thru CONS6.

The second string of factors could be WC1 thru WC8 if that's what the user enters in the inputbox.

Essentially the string is everything in the selection separated by the comma.

Later in the document I will use these bookmarks to create a cross reference.
Attached Files
File Type: docx Sample.docx (14.7 KB, 7 views)
Reply With Quote
  #4  
Old 08-16-2019, 05:10 AM
gmaxey gmaxey is offline Create bookmark from comma separated text Windows 10 Create bookmark from comma separated text Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Jeffery,

I'm sorry I can't help more but I just don't understand what you are trying to do.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 08-18-2019, 06:00 AM
jeffreybrown jeffreybrown is offline Create bookmark from comma separated text Windows Vista Create bookmark from comma separated text Office 2007
Expert
Create bookmark from comma separated text
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Does anybody else have an idea? Basically instead of manually creating a bunch of bookmarks, I would like VBA to create bookmarks from the selected text which is separated by a comma. The name can simple be in sequence which would be proceeded by the word entered into an inputbox by the user.
Reply With Quote
  #6  
Old 08-18-2019, 07:51 AM
gmaxey gmaxey is offline Create bookmark from comma separated text Windows 10 Create bookmark from comma separated text Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Almost anyone could help if you would provide a clear explanation of what you want.

Post a document showing some text, what you want selected and what you want the result to be after the code runs.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 08-18-2019, 01:46 PM
jeffreybrown jeffreybrown is offline Create bookmark from comma separated text Windows Vista Create bookmark from comma separated text Office 2007
Expert
Create bookmark from comma separated text
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Sorry about that, but sure thought the attachment in post #3 had the clear explanation and example.

The user is going to highlight X1, X2, X3, X4, X5, X6 which is in a paragraph.

When the code runs, the user will be prompted via an inputbox to add a descriptor for the bookmarks.

In the sample, the user highlights X1, X2, X3, X4, X5, X6 and then upon running the macro they enter CONS in the inputbox.

After the code runs there are now 6 bookmark titled, CONS1, CONS2, CONS3, etc which is in the sample.

I'm not sure what part of the explanation I am missing, but hopefully this completes it. Thank you for your help.
Attached Files
File Type: docx Sample.docx (14.3 KB, 7 views)
Reply With Quote
  #8  
Old 08-18-2019, 01:59 PM
gmaxey gmaxey is offline Create bookmark from comma separated text Windows 10 Create bookmark from comma separated text Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Based on what you have shown and described:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim varFactors
Dim lngIndex As Long
Dim strFind As String
Dim oRng As Range
Dim strDesc As String

  varFactors = Split(Selection.Text, ",")
  strDesc = InputBox("Enter a decriptor")
  For lngIndex = 0 To UBound(varFactors)
    Set oRng = ActiveDocument.Range
    With oRng.Find
      .Text = Trim(varFactors(lngIndex))
      .MatchCase = True
      While .Execute
        If oRng.InRange(Selection.Range) Then
          'If you need to expand the range of the defined text do it here before applying the BM
          oRng.Bookmarks.Add strDesc & lngIndex + 1, oRng
        End If
        oRng.Collapse wdCollapseEnd
      Wend
    End With
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 08-18-2019, 02:05 PM
jeffreybrown jeffreybrown is offline Create bookmark from comma separated text Windows Vista Create bookmark from comma separated text Office 2007
Expert
Create bookmark from comma separated text
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

This is absolutely perfect Greg. Thank you for your time.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
using bookmark feature in Word to create index Indexer Word 6 02-19-2017 12:28 PM
Create bookmark and use it in macrobutton fusion001 Word VBA 3 05-28-2015 02:00 AM
Create bookmark from comma separated text Nest IF statements with a text comma inbetween each IF statement AClaborn Excel 2 01-20-2015 12:07 PM
Create bookmark from comma separated text Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control skarden Word 1 12-12-2011 10:39 PM
adding text on a separated column line ahmet1985 Word 0 03-27-2010 07:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft