|
#1
|
|||
|
|||
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:
|
#2
|
|||
|
|||
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
|
#3
|
||||
|
||||
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 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 |
#4
|
||||
|
||||
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.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
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. |
#6
|
||||
|
||||
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 |
#7
|
|||
|
|||
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) |
#8
|
||||
|
||||
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 |
#9
|
|||
|
|||
What IDE or code editor do you use for vba word?
|
#10
|
||||
|
||||
For me it is Word's own VBA Editor - opened from Word by pressing Alt-F11
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#11
|
|||
|
|||
Yeah yeah, I work with that one. I was asking if you knew something better
|
#12
|
|||
|
|||
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. |
#13
|
|||
|
|||
The document.
I forgot to upload the document
|
#14
|
|||
|
|||
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? |
#15
|
|||
|
|||
Sorry, too long procedure is in the form
|
|
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 |
Deleting only all bookmarks contents not the bookmarks | adilprodigy | Word VBA | 1 | 10-11-2017 01:31 PM |
Form updating Bookmarks - writes to the bookmarks multiple times | PeterPlys | Word VBA | 13 | 01-14-2015 06:41 AM |
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 |