Consulting

Results 1 to 6 of 6

Thread: Insert Bookmark data from one Word File into another Word file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jul 2024
    Posts
    5
    Location

    Question Insert Bookmark data from one Word File into another Word file

    Hi,

    Just to start, i'm new with VBA and i'm having a hard time understanding the code. I got a good share done with code I found online. But now I want to do something and I can't find what i'm looking for.
    Second my native language is Dutch so if my english doesn't make sense. I do apologise up front, i'm doing the best i can
    If you can give me a direction where to look, I would already be glad. I searched the database but I couldn't find the information i needed. I hope someone will be able to help me out.

    What i did was build a UserForm to enter data like the name of a project, the project owner, etc. This information can be inserted. I can recall the form, have the form read the bookmarks again, edit the information and insert the data back into the document. Which all works like a charm. The next step is to read these bookmarks into another Word file. In my company we make different document where we need the same information over and over again.
    What i like to do is be able to open a new document (which are all standardised documents) let a UserForm pop up. Let me choose another document and have it read the bookmarks in that document. So the information that is already in the other document is inserted in this new Userform. So we don't have to fill out the same fields over and over again. I don't want it to be send directly to the bookmarks. But have the data inserted in to the fields in the userform so they can be edited.

    I know there is a way but i have no clue how to get there.

    This is what I have but it only opens the other document but doesn't read the bookmarks.
    Also now it is a set document and i want is to give the user the choice of which document to read. I know I need to name the bookmarks the same in every file which is fine. I'm importing the data in to the documents anyway.
    Reason is that our files start with the number of the project so with each project the file name will be different. So a set document in the VBA code like the example is not an option.


    Private Sub CommandButton12_Click()
        Dim strDocName As String
        strDocName = "Y:\03. Marketing\03. Documenten\Sjablonen\20230714 Sjablonen nieuw\01.Offerte met Macro's DEF 00-0 mme.dotm"
        Dim SrcDoc As Word.Document
        Dim DestDoc As Word.Document
        Set DestDoc = ActiveDocument
        Set SrcDoc = Documents.Open(strDocName)
        DestDoc.FormFields("Me.Ftitelof.Text").Result = SrcDoc.FormFields("TITofferte").Result
        DestDoc.FormFields("Me.FprojectName.Text").Result = SrcDoc.FormFields("projectName").Result
        DestDoc.FormFields("Me.Freferentie.Text").Result = SrcDoc.FormFields("REFra").Result
        DestDoc.FormFields("Me.Fog.Text").Result = SrcDoc.FormFields("Opdrachtgever").Result
    End Sub
    Last edited by Aussiebear; 07-24-2024 at 04:42 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •