#16
|
||||
|
||||
Quote:
Code:
Private Sub CommandButton2_Click() Dim oCC As ContentControl 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, "|") For Each oCC In ActiveDocument.ContentControls Select Case oCC.Title Case Is = "termino" oCC.Range.Text = arr(0) Case Is = "partido" oCC.Range.Text = arr(1) End Select Next oCC End If lbl_Exit: Set oCC = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#17
|
||||
|
||||
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 |
#18
|
|||
|
|||
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. |
#19
|
|||
|
|||
Perfect
This code works perfect. One question, is it possible to put decimal values? Instead of "If lPK > 81 And lPK < 85 Then..." something like that "If lPK > 81.720 And lPK < 85.240 Then..."
Quote:
|
#20
|
||||
|
||||
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 |
#21
|
|||
|
|||
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) |
#22
|
||||
|
||||
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 |
#23
|
|||
|
|||
What IDE or code editor do you use for vba word?
|
#24
|
||||
|
||||
For me it is Word's own VBA Editor - opened from Word by pressing Alt-F11
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#25
|
|||
|
|||
Yeah yeah, I work with that one. I was asking if you knew something better
|
#26
|
|||
|
|||
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. |
#27
|
|||
|
|||
The document.
I forgot to upload the document
|
#28
|
|||
|
|||
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? |
#29
|
|||
|
|||
Sorry, too long procedure is in the form
|
#30
|
||||
|
||||
I provided what I thought were quite valid ways to simplify the coding effort and streamline the operation of what you were trying to do. You've ignored those suggestions to date. If you want to solve your issue, go back through this thread and spend some time reading and understanding what was already offered.
The absolute shortest way to do the coding is to read the values from an Excel spreadsheet. Coding all the values as you have been doing is simply not efficient and useful only for demonstration purposes.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
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 |