Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-06-2021, 02: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: 36
gorkac is on a distinguished road
Default Help with bookmarks in word.

Hi.
I am creating a form for Word that works with multiple bookmarks, a combo, etc.
It consists of:

1 form: with code to fill in the bookmarks and clean them.
Several modules and 1 combobox for VIA. The Word sheet has markers: denomination, term and party.

The combo will load 1 data "VIA" and a numerical value "PK".
for example: for "VIA" = NA-3010 and for "PK" = 12
So for each VIA.



I also need that, if I choose between PK 0 and 12, in the "termino" bookmark put a data: CORTES
If I choose between PK 12.1 and 20, in the "termino" bookmark put another different data: BUĐUEL
and if I choose between PK 21 and 32, in the "termino" bookmarks indicate: FUSTIĐANA and so on.
To make matters worse, the "match" bookmarks can also vary the data, depending on all of the above.
I would need the simplest code, because I am not going to work only with two conditions, I explain:
There are highways, for example the N-121, which has several "termino", some of these terminos depend on one party or another.
Sorry to bother but I got stuck.
I upload the file.

Thanks in advance.
Attached Files
File Type: dotm Plantilla carreteras.dotm (23.3 KB, 2 views)
Reply With Quote
  #2  
Old 08-06-2021, 08:26 PM
gmayor's Avatar
gmayor gmayor is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 3,576
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

Your attachment does not contain any code?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 08-07-2021, 03:21 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: 36
gorkac is on a distinguished road
Default Sorry

Quote:
Originally Posted by gmayor View Post
Your attachment does not contain any code?
The pdf "TERMINOS Y KILOMETROS" is what I need to pass to the Word form, but I only filled in the VIA and the Pk completed the bookmark named denominacion, termino and partido.
it is understood?

Sorry for my english.
Attached Files
File Type: pdf TERMINOS Y KILOMETROS.pdf (480.1 KB, 7 views)
File Type: dotm PLANTILLA NUEVA SIP automatica.dotm (45.2 KB, 6 views)
File Type: docx WHAT I WANT.docx (67.3 KB, 2 views)
Reply With Quote
  #4  
Old 08-07-2021, 11:27 PM
gmayor's Avatar
gmayor gmayor is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 3,576
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

Frankly I have no idea what it is that you are trying to do, not helped by my unfamiliarity with Spanish.

Your 'What I Want' document seems to bear no relationship to your template, and trying to work with a PDF file of data is not really practicable. I would start by opening that PDF in Word and save it as a document. You can then populate your userform combobox as follows:


Code:
Dim oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim sName As String

    Set oDoc = Documents.Open(ThisDocument.Path & "\TERMINOS Y KILOMETROS.docx")
    For Each oTable In oDoc.Tables
        Set oRng = oTable.Cell(1, 1).Range
        oRng.End = oRng.End - 1
        sName = Split(oRng.Text, " ")(0)
        cbovia.AddItem sName
    Next oTable

As for the rest it is anyone's guess what you want. However if you have the converted data document open you can interrogate the tables to get what information you want for your document.


I would suggest that you use content controls, rather than bookmarks which are easily deleted.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 08-08-2021, 03: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: 36
gorkac is on a distinguished road
Post

Sorry, FORGET the pdf document "TERMS AND KILOMETERS" and the word document "WHAT I WANT".

Let's start over.

I have a word document named , when one user open it, this form appears:

The user will enter a "VIA" and a "PK".

Example: if in the "VIA" combo user enter A-68 and in the textbox: 12,
I need that in the bookmarkers "termino", "denominacion" and "partido", it is filled automatically with and put "Tudela" in the marker "termino"; "Cortes-Bu˝uel" on the "denominacion" bookmark and "Tudela" on the "partido" bookmark.
I leave some photos to show the idea.
Attached Images
File Type: png Captura.PNG (6.5 KB, 20 views)
File Type: png Captura1.PNG (7.8 KB, 20 views)
Reply With Quote
  #6  
Old 08-08-2021, 03:50 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: 36
gorkac is on a distinguished road
Default

When the user clicks "Aceptar", the bookmarks are automatically filled in in word.
This is what I need to program.
Help me please.
Attached Images
File Type: png Captura2.PNG (63.2 KB, 20 views)
Reply With Quote
  #7  
Old 08-08-2021, 04:05 AM
gmayor's Avatar
gmayor gmayor is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 3,576
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

OK. A-68 and 12 come from the userform. Where do the other pieces of information 'denominacion'. 'termino' and 'partido' come from?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #8  
Old 08-08-2021, 04:35 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: 36
gorkac is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
OK. A-68 and 12 come from the userform. Where do the other pieces of information 'denominacion'. 'termino' and 'partido' come from?
That is what I want to program.
Reply With Quote
  #9  
Old 08-08-2021, 04:56 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: 36
gorkac is on a distinguished road
Default

In the combobox "CargarCarreteras" I already have the items I need to fill the "VIA" bookmark.

In the Module "formulario" I have the code created by you to fill markers, I have called it "Rellenar"(in English it is written "Fill"):

#Public Sub Fill(strMarkerName As String, strValue As String).
'Gorka Cuairan. Function that fills markers
Dim Rng As Range
With ActiveDocument
On Error GoTo lbl_Exit
Set Rng = .Bookmarks(strMarkerName).Range
Rng.Text = strValue
Rng.Bookmarks.Add strMarkerName
End With
lbl_Exit:
Set Rng = Nothing
Exit Sub
End Sub

The idea is that in the Module "termino", I enter the values I need, but I don't know how to do it and I don't know how to pass it to the variable strValue of the previous procedure.

The same for the Modules "denominacion" and "partido".
Reply With Quote
  #10  
Old 08-08-2021, 08:44 PM
gmayor's Avatar
gmayor gmayor is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 3,576
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

The 'Fill' macro will write the values to the document.e.g. from your document
Code:
Private Sub CommandButton2_Click()        'BOTON Limpiar'
Dim i As Long
Dim strNombre As String
    For i = 1 To ActiveDocument.Bookmarks.Count
        strNombre = ActiveDocument.Bookmarks(i).Name
        Select Case strNombre
            Case Is = "via"
                Rellenar strNombre, cbovia.Value
            Case Is = "kilometro"
                Rellenar strNombre, txtpk.Text
            Case Is = "partido"
                Rellenar strNombre, "partido value"
            Case Is = "termino"
                Rellenar strNombre, "termino value"
        End Select
    Next i
lbl_Exit:
    Exit Sub
End Sub
Note that you cannot fill a bookmark with nothing.

Or if you follow my suggestion and replace the bookmarks with content controls (Insert Content Control Add-In will do that) then
Code:
Private Sub CommandButton2_Click()        'BOTON Limpiar'
Dim oCC As ContentControl
    For Each oCC In ActiveDocument.ContentControls
        Select Case oCC.Title
            Case Is = "via"
                oCC.rage.Text = cbovia.Value
            Case Is = "kilometro"
                oCC.Range.Text = txtpk.Text
            Case Is = "partido"
                oCC.Range.Text = "partido value"
            Case Is = "termino"
                oCC.Range.Text = "termino value"
        End Select
    Next oCC
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
Reply With Quote
  #11  
Old 08-17-2021, 04:15 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: 36
gorkac is on a distinguished road
Default

I'm sorry I didn't answer before, I've been away for a few days.
I am not able to obtain the desired result, I insist that you can give me a practical example:



I am confident that you teach me to program one of the examples EXAMPLE 1 or EXAMPLE 2, I would do the rest.



Thank you very much for your patience.
Attached Images
File Type: png 1.png (67.1 KB, 17 views)
File Type: png 2.png (91.9 KB, 16 views)
Reply With Quote
  #12  
Old 08-17-2021, 04:52 AM
gmayor's Avatar
gmayor gmayor is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 3,576
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

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
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #13  
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: 36
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
  #14  
Old 08-17-2021, 07:47 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: 36
gorkac is on a distinguished road
Default

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
Is this that you just wrote possible to do with?
https://www.gmayor.com/insert_content_control_addin.html?
Reply With Quote
  #15  
Old 08-17-2021, 07:10 PM
Guessed's Avatar
Guessed Guessed is offline Help with bookmarks in word. Windows 10 Help with bookmarks in word. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,638
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
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
Reply

Thread Tools
Display Modes


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 12:19 AM.


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