Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-31-2021, 09:56 PM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default

Hi Mr. Mayor. I need a last favor.


In the same document, there are parts to fill in with the same bookmarks, but Word does not allow repeating the name of the bookmarks "termino", and so on. What lines can I add so that I fill in a new bookmark named "termino2", for example, what is filled in the marker "termino"?

Quote:
Originally Posted by gmayor View Post
You probably need something like the following, but if there are lots of these values as seems to be the case you would be better putting the codes and their values in an Excel worksheet and reading them from the worksheet.

Code:
Private Sub CommandButton2_Click()
Dim sVia As String
Dim lPK As String
    sVia = ComboVia.Text
    lPK = textPK.Value
    Select Case sVia
        Case Is = "A-68"
            If lPK > 81 And lPK < 85 Then
                Rellenar "termino", "Castejon"
                Rellenar "partido", "Tudela"
            End If
            If lPK > 84 And lPK < 99 Then
                Rellenar "termino", "Corella"
                Rellenar "partido", "Estella"
            End If
            If lPK > 98 And lPK < 113 Then
                Rellenar "termino", "Fontellas"
                Rellenar "partido", "Tafalla"
            End If
        Case Is = "NA-3010"
            If lPK > 20 And lPK < 25 Then
                Rellenar "termino", "Cortes"
                Rellenar "partido", "Tudela"
            End If
            If lPK > 24 And lPK < 35 Then
                Rellenar "termino", "Ribaforada"
                Rellenar "partido", "Tafalla"
            End If
            If lPK > 34 And lPK < 44 Then
                Rellenar "termino", "Novillas"
                Rellenar "partido", "Estella"
            End If
    End Select
lbl_Exit:
    Exit Sub
End Sub
Reply With Quote
  #2  
Old 08-17-2021, 06:30 AM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default

Oh, wow, I wouldn't know how to thank you for so much help. I'll get down to business with the code. If I have any further questions, I will let you know. Many thanks
Reply With Quote
  #3  
Old 08-17-2021, 07:10 PM
Guessed's Avatar
Guessed Guessed is online now Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,999
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can simplify your code to make it faster to implement and maintain.
For instance, I would get rid of the Carreteras module and replace the UserForm_Activate macro in the userform's module with this to streamline that part.
Code:
Private Sub UserForm_Initialize()
  Dim sVia As String, arr() As String
  sVia = "AP-15:AP-68:A-1:A-10:A-12:A-15:A-21:A-68:PA-30:PA-31:PA-32:PA-33:PA-34:N-111:" & _
          "N-113:N-121:N-121-A:N-121-B:N-121-C:N-135:N-232:N-240:N-240-A"
  arr = Split(sVia, ":")
  Me.cbovia.List = arr
End Sub
Do you have a spreadsheet or table to read the possible exit values? That would make loading the dependent exits a lot more streamlined.

If you are going to enter all that data directly in VBA code, try to do it with as little duplication or complexity as possible. Graham's code could also be trimmed a bit along these lines
Code:
Private Sub CommandButton2_Click()
  Dim sVia As String, lPK As String, sTermPart As String, arr() As String
  sVia = ComboVia.Text
  lPK = textPK.Value
  Select Case sVia
    Case Is = "A-68"
      If lPK < 85 Then
        sTermPart = "Castejon|Tudela"
      ElseIf lPK < 99 Then
        sTermPart = "Corella|Estella"
      Else
        sTermPart = "Fontellas|Tafalla"
      End If
    Case Is = "NA-3010"
      If lPK < 25 Then
        sTermPart = "Cortes|Tudela"
      ElseIf lPK < 35 Then
        sTermPart = "Ribaforada|Tafalla"
      Else
        sTermPart = "Novillas|Estella"
      End If
  End Select
  If UBound(arr) > 0 Then
    arr = Split(sTermPart, "|")
    Rellenar "termino", arr(0)
    Rellenar "partido", arr(1)
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 08-18-2021, 01:55 AM
Guessed's Avatar
Guessed Guessed is online now Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,999
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I've looked over all this thread and think the solution is growing in complexity with considerable repetitive code to still be written.

I suggest taking a reset and look at this from a different perspective. Attached is an example which aligns with what I think the OP wanted. It avoids the userform in favour of mapped Content Controls and either CC properties or macros to populate the CC values.
Attached Files
File Type: docm DemoHighwayCCs.docm (37.8 KB, 5 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 08-18-2021, 02:20 AM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default

Thank you very much, I will try it. I can't put the code like this "If lPK <85 Then ..." because they are roads and their miles (kilometros). Depending on which miles we talk between, one "termino" or another will be written. PK are "kilometros" (unit of measurement on European roads, you use the mile).
There are roads ("carreteras") that do not start at zero, but can start at mile (kilometro) 12.400 and end at mile (kilometro) 36.700, for example.
Reply With Quote
  #6  
Old 08-18-2021, 03:48 PM
Guessed's Avatar
Guessed Guessed is online now Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,999
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Are you planning on coding all the information or read it from a table?

It is not a stretch to deal with decimal places or starting distances but you need to decide on how all the data is going to be sourced.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 08-18-2021, 04:00 PM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default

I code all the information, I have already started and it works fine.
How do I implement error checks? If I have a value that does not exist, how do I not fill in what I want?
Example:
Case Is = "NA-3010"
If lPK > 20 And lPK < 25 Then
Rellenar "termino", "Cortes"
Rellenar "partido", "Tudela"
End If
If lPK > 24 And lPK < 35 Then
Rellenar "termino", "Ribaforada"
Rellenar "partido", "Tafalla"
End If
If lPK > 34 And lPK < 44 Then
Rellenar "termino", "Novillas"
Rellenar "partido", "Estella"
End If
End Select
As I control in the case that the user enters for example the lPK 67 (does not exist)
Reply With Quote
  #8  
Old 08-18-2021, 04:14 PM
Guessed's Avatar
Guessed Guessed is online now Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,999
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You need to join the If statements to isolate the invalid ranges. Look back over the provided code for instances of ElseIf to see the structure you need to show invalid distances. The basic premise is as follows.

If test then
' do something
ElseIf test2 then
' do something else
Else
' what happens when the distance isn't valid
End If
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #9  
Old 08-19-2021, 12:21 PM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default

What IDE or code editor do you use for vba word?
Reply With Quote
  #10  
Old 08-19-2021, 03:18 PM
Guessed's Avatar
Guessed Guessed is online now Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,999
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

For me it is Word's own VBA Editor - opened from Word by pressing Alt-F11
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #11  
Old 08-20-2021, 10:02 AM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default

Yeah yeah, I work with that one. I was asking if you knew something better
Reply With Quote
  #12  
Old 08-21-2021, 12:04 PM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default

Hi guys, one last help. As the procedure is very long, I get an error.
I'll give you the file, let's see how I can divide the "carreteras" routine into several parts. Notice, I still have to insert half of the information.

Thanks in advance.
Reply With Quote
  #13  
Old 08-21-2021, 12:07 PM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default The document.

I forgot to upload the document
Attached Files
File Type: dotm PLANTILLA NUEVA SIP automatica (2).dotm (164.5 KB, 6 views)
Reply With Quote
  #14  
Old 08-21-2021, 12:25 PM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default

I see that the problem is that in the same procedure, I have written more than 6000 lines of code.
How can i divide it?
Reply With Quote
  #15  
Old 08-21-2021, 12:48 PM
gorkac gorkac is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Advanced Beginner
Help with bookmarks in word.
 
Join Date: Jul 2021
Posts: 62
gorkac is on a distinguished road
Default

Sorry, too long procedure is in the form
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving a word doc as a pdf with bookmarks MimiCush Word 10 03-26-2018 01:51 PM
Help with bookmarks in word. Deleting only all bookmarks contents not the bookmarks adilprodigy Word VBA 1 10-11-2017 01:31 PM
Help with bookmarks in word. Form updating Bookmarks - writes to the bookmarks multiple times PeterPlys Word VBA 13 01-14-2015 06:41 AM
Help with bookmarks in word. selecting ms word bookmarks using vba dnc Word VBA 4 05-10-2013 04:58 PM
word 2007 bookmarks Dawn Word 0 07-14-2009 01:00 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:19 AM.


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