+ Reply to Thread
Results 1 to 19 of 19

Add a vbCrLF

  1. #1
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Add a vbCrLF

    I want to exporting some data from Excel 2010 to specific bookmarks in a Word document (template)

    The first bookmark already exist in the Word document. The next couple of bookmarks do not exist already because the are different each time. (user can decide by a macro buttons in excel with bookmarks should be added.)

    Starting my marco in excel, it opens the document and it finds the basic bookmark. The cursor is put on the right place. But then I can't figure out what should be the code to add a vbCrLF to get the cursor on the next blank line in that Word document.
    I'am trying differt code with Chr10 or vbCrLF on the same code row or a new one but I can't find the solution.



    Complete function code, so far:

    Dim wrdApp As Object
    Dim wrdDoc As Object
    Dim oRng As Object

    Dim wdDoc As Word.Document

    On Error Resume Next
    Set wrdApp = GetObject(, "Word.Application")
    If Err Then
    Set wrdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0

    wrdApp.Visible = True

    Set wrdDoc = wrdApp.Documents.Add(Template:="C:\local\DD.dotx")
    Set oRng = wrdDoc.Paragraphs(1).Range

    With wrdApp
    '.Documents.Open "C:\local\DD.dotx"
    wrdApp.Selection.Goto What:=wdGoToBookmark, Name:="DD"

    End With

    End Sub


    Does anybody know a solution for this?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add a vbCrLF

    Can you add code tags when posting code?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add a vbCrLF

    Does this work?
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    Norie,

    Thanks for your answer.
    Unfortunatly it does not functioning.

    I recieve an error:
    Error 438
    This propterty of methode is not supported by this object

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add a vbCrLF

    Slight typo, it should have been this.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    That does'nt work and I recieve no error.

    I tested it and
    Please Login or Register  to view this content.
    is function well. Only the last part, replace the "123" for a code that gives a vbCrLF (Chr13) is the problem.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add a vbCrLF

    Strange, it seems to work for me.

    For example this code will put a line between Test1 and Test2.
    Please Login or Register  to view this content.
    What are you doing after moving to a new line?

  9. #9
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    Norie,

    Your code works fine but is not what I 'am looking for.

    My Word document looks like:

    "bla bla
    I

    bla...bla...


    The "I" is the basis bookmark. When I run the macro then the cursor is blinking there. Thats fine. But now I like to insert a new row there and add a new bookmark in front off that line.

  10. #10
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    After insert an new line there, the result should be that there are two line's with both a bookmakers sign on the first position. The first bookmakers sign was there already, the second is added by the macro.

    "bla..bla.."

    I
    I


    "bla..bla..

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add a vbCrLF

    Do you mean you want to add a new bookmark on the next line down?

  12. #12
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    yes that is what my goal is.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add a vbCrLF

    This might be stupid question but, why do you want/need to insert a new bookmark into the document?

  14. #14
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    Pherhaps my thoughts on controlling bookmarks (add/remove) in a Word document from macro's in excel is not possible.

    Thats why I try to find another solution.
    Is is possible to create a macro in excel which delete empty tables in a Word document. I read many artikels online on how to delete empty rows but I looking for a solution to delete complete tables.
    I have a Word document with 5 different tables. This tables are filled with data exported from Excel. Each table has some bookmarks in it. Depending on the user, while working in excel, one or more tables are filled with the data. The empty tables should be removed.

    Is this possible?

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add a vbCrLF

    Yes, it's possible

    A Word document contains a collection of Tables which consists of all the Table objects in the document.

    You can add/edit/delete etc tables via that collection.

  16. #16
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    Thanks for your reply.

    Do you have sample macro for that. I look on Internet, see some code but it does not function in a test.
    I also wonder how I can find the unigue name of a table in Word. When I see the properties, there is no name or something what indicates its unique id where I can refer to in a macro.

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add a vbCrLF

    I could probably post some sample macros/code but I've no idea if they would help.

    It might help if you could upload an example of what you are working with and explain a little what you are trying to do.

  18. #18
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    I see on internet some code but testing it and make some changes and test again give me errors. I am no expert in VBA, so do you have a basic code for this goal. Then I can start from there creating it.

  19. #19
    Registered User
    Join Date
    07-11-2012
    Location
    Amsterdam, holland
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add a vbCrLF

    I have created two example files of my situatie, see attachment.
    Place the files in c:\test\..

    Open the excel file and there are some items you can select.
    First group off items (Basic) are always exported to Word and placed in a table there (with bookmarks)
    The next two groups are variable. Some times thy are not filled in and if that is the case then I like to remove the table corresponding to this variable in the WWord document.

    When you have selected some items, then click on the button. It opens the word document, fill the table with the selected values. What it should do more is that it has to delete the tables who are not necessary. It is not necessary when there is nothing selected at that variable in Excel

    (there is an (bookmark) error in the macro when you do not fill in an answer in this test document, I know that)But for the explenation it is not an issue.

    I hope this gives you a better idea of my goal.
    Attached Files Attached Files
    Last edited by Harry Hof; 11-28-2014 at 07:03 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. What is vbCrLF & _
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-14-2014, 06:30 PM
  2. Remove multiple instances of VBCRLF
    By rolta100 in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 12-06-2013, 07:44 AM
  3. [SOLVED] Trim 'vbCrLf' from end of a string
    By Shane O in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-28-2012, 10:31 AM
  4. vbCrLf and Chr(10) produce square(s)
    By Jeroen1000 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-01-2009, 04:57 AM
  5. Compile Error in Excel 2004 when Inputbox contains "VBCRLF"
    By QTP Professional in forum Excel General
    Replies: 1
    Last Post: 11-18-2005, 07:50 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1